updated contrib modules
This commit is contained in:
@@ -34,6 +34,9 @@ profile.type.*:
|
||||
use_revisions:
|
||||
type: boolean
|
||||
label: 'User revisions'
|
||||
description:
|
||||
type: text
|
||||
label: 'Description'
|
||||
|
||||
field.field.*.*.*.third_party.profile:
|
||||
type: mapping
|
||||
|
||||
@@ -10,8 +10,8 @@ dependencies:
|
||||
- views
|
||||
- system (>=8.1.0)
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-06-12
|
||||
version: '8.x-1.0-beta1'
|
||||
# Information added by Drupal.org packaging script on 2017-09-19
|
||||
version: '8.x-1.0-rc1'
|
||||
core: '8.x'
|
||||
project: 'profile'
|
||||
datestamp: 1497287652
|
||||
datestamp: 1505830148
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
entity.profile.collection:
|
||||
title: 'User profiles'
|
||||
description: 'Manage profile types, including fields, and profiles for users.'
|
||||
title: 'Profiles'
|
||||
description: 'Manage user profiles.'
|
||||
route_name: entity.profile.collection
|
||||
parent: entity.user.collection
|
||||
|
||||
entity.profile_type.collection:
|
||||
title: 'Profile types'
|
||||
description: 'Manage profile types, including fields.'
|
||||
route_name: entity.profile_type.collection
|
||||
parent: user.admin_index
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
# Tabs on the profile admin page
|
||||
# Tabs on the user admin page
|
||||
entity.profile.collection_tab:
|
||||
route_name: entity.profile.collection
|
||||
base_route: entity.profile.collection
|
||||
base_route: entity.user.collection
|
||||
title: 'Profiles'
|
||||
weight: 10
|
||||
|
||||
entity.profile_type.collection_tab:
|
||||
route_name: entity.profile_type.collection
|
||||
base_route: entity.profile.collection
|
||||
title: 'Profile types'
|
||||
entity.profile_type.edit_form:
|
||||
title: 'Edit'
|
||||
route_name: entity.profile_type.edit_form
|
||||
base_route: entity.profile_type.edit_form
|
||||
|
||||
# Add tabs for each profile type
|
||||
entity.profile.user_profile_form:
|
||||
|
||||
@@ -88,7 +88,7 @@ function template_preprocess_profile(array &$variables) {
|
||||
$profile = $variables['elements']['#profile'];
|
||||
|
||||
$variables['profile'] = $profile;
|
||||
$variables['url'] = $profile->toUrl();
|
||||
$variables['url'] = $profile->id() ? $profile->toUrl() : FALSE;
|
||||
// Helpful $content variable for templates.
|
||||
$variables['content'] = [];
|
||||
foreach (Element::children($variables['elements']) as $key) {
|
||||
@@ -311,7 +311,9 @@ function profile_views_add_title_pre_render($element) {
|
||||
/** @var \Drupal\views\ViewExecutable $view */
|
||||
if (isset($element['#title'])) {
|
||||
$view = $element['view_build']['#view'];
|
||||
$view->setTitle($element['#title']);
|
||||
if (!empty($view->result)) {
|
||||
$view->setTitle($element['#title']);
|
||||
}
|
||||
}
|
||||
|
||||
return $element;
|
||||
@@ -351,6 +353,16 @@ function profile_views_data_alter(&$data) {
|
||||
'base field' => 'uid',
|
||||
'field' => 'uid',
|
||||
];
|
||||
$data['users_field_data']['profile_type']['relationship'] = [
|
||||
'title' => t('Profile Type'),
|
||||
'label' => t('Profile Type'),
|
||||
'group' => 'User',
|
||||
'help' => t('Reference to a specific profile type of a user.'),
|
||||
'id' => 'profile_relationship',
|
||||
'base' => 'profile',
|
||||
'base field' => 'uid',
|
||||
'field' => 'uid',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# edit_form, delete_form routes are generated by DefaultHtmlRouteProvider.
|
||||
entity.profile.collection:
|
||||
path: '/admin/config/people/profiles'
|
||||
path: '/admin/people/profiles'
|
||||
defaults:
|
||||
_entity_list: 'profile'
|
||||
_title: 'Profiles'
|
||||
@@ -8,7 +8,7 @@ entity.profile.collection:
|
||||
_permission: 'administer profile'
|
||||
|
||||
entity.profile_type.collection:
|
||||
path: '/admin/config/people/profiles/types'
|
||||
path: '/admin/config/people/profiles'
|
||||
defaults:
|
||||
_entity_list: 'profile_type'
|
||||
_title: 'Profile types'
|
||||
@@ -16,7 +16,7 @@ entity.profile_type.collection:
|
||||
_permission: 'administer profile types'
|
||||
|
||||
entity.profile_type.add_form:
|
||||
path: '/admin/config/people/profiles/types/add'
|
||||
path: '/admin/config/people/profiles/add'
|
||||
defaults:
|
||||
_entity_form: profile_type.add
|
||||
_title: 'Add'
|
||||
|
||||
@@ -134,7 +134,7 @@ class ProfileController extends ControllerBase implements ContainerInjectionInte
|
||||
$build['add_profile'] = Link::createFromRoute(
|
||||
$this->t('Add new @type', ['@type' => $profile_type->label()]),
|
||||
'entity.profile.type.user_profile_form.add',
|
||||
['user' => $this->currentUser()->id(), 'profile_type' => $profile_type->id()])
|
||||
['user' => $user->id(), 'profile_type' => $profile_type->id()])
|
||||
->toRenderable();
|
||||
|
||||
// Render the active profiles.
|
||||
|
||||
@@ -219,15 +219,6 @@ class Profile extends ContentEntityBase implements ProfileInterface {
|
||||
$this->setDefault(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
// Mark a new revision if the profile type supports revisions, and if there
|
||||
// has been field data changes.
|
||||
if ($this->hasTranslationChanges()) {
|
||||
/** @var \Drupal\profile\Entity\ProfileTypeInterface $profile_type */
|
||||
$profile_type = \Drupal::entityTypeManager()->getStorage('profile_type')->load($this->bundle());
|
||||
$this->setNewRevision($profile_type->shouldCreateNewRevision());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\profile\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
||||
use Drupal\Core\Entity\EntityDescriptionInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
|
||||
/**
|
||||
@@ -39,14 +40,15 @@ use Drupal\Core\Entity\EntityStorageInterface;
|
||||
* "weight",
|
||||
* "status",
|
||||
* "langcode",
|
||||
* "use_revisions"
|
||||
* "use_revisions",
|
||||
* "description"
|
||||
* },
|
||||
* links = {
|
||||
* "add-form" = "/admin/config/people/profiles/types/add",
|
||||
* "delete-form" = "/admin/config/people/profiles/types/manage/{profile_type}/delete",
|
||||
* "edit-form" = "/admin/config/people/profiles/types/manage/{profile_type}",
|
||||
* "admin-form" = "/admin/config/people/profiles/types/manage/{profile_type}",
|
||||
* "collection" = "/admin/config/people/profiles/types"
|
||||
* "add-form" = "/admin/config/people/profiles/add",
|
||||
* "delete-form" = "/admin/config/people/profiles/manage/{profile_type}/delete",
|
||||
* "edit-form" = "/admin/config/people/profiles/manage/{profile_type}",
|
||||
* "admin-form" = "/admin/config/people/profiles/manage/{profile_type}",
|
||||
* "collection" = "/admin/config/people/profiles"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
@@ -73,6 +75,13 @@ class ProfileType extends ConfigEntityBundleBase implements ProfileTypeInterface
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
/**
|
||||
* A brief description of the profile type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* Whether the profile type is shown during registration.
|
||||
*
|
||||
@@ -175,6 +184,21 @@ class ProfileType extends ConfigEntityBundleBase implements ProfileTypeInterface
|
||||
return $this->use_revisions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription() {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setDescription($description) {
|
||||
$this->description = $description;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -186,5 +210,4 @@ class ProfileType extends ConfigEntityBundleBase implements ProfileTypeInterface
|
||||
system_rebuild_module_data();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,11 +4,12 @@ namespace Drupal\profile\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
use Drupal\Core\Entity\RevisionableEntityBundleInterface;
|
||||
use Drupal\Core\Entity\EntityDescriptionInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface defining a profile type entity.
|
||||
*/
|
||||
interface ProfileTypeInterface extends ConfigEntityInterface, RevisionableEntityBundleInterface {
|
||||
interface ProfileTypeInterface extends ConfigEntityInterface, RevisionableEntityBundleInterface, EntityDescriptionInterface {
|
||||
|
||||
/**
|
||||
* Return the registration form flag.
|
||||
|
||||
@@ -59,6 +59,21 @@ class ProfileForm extends ContentEntityForm {
|
||||
$form_state->setValue('status', FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildEntity(array $form, FormStateInterface $form_state) {
|
||||
/** @var \Drupal\profile\Entity\ProfileInterface $entity */
|
||||
$entity = parent::buildEntity($form, $form_state);
|
||||
|
||||
// Mark a new revision if the profile type enforces revisions.
|
||||
/** @var \Drupal\profile\Entity\ProfileTypeInterface $profile_type */
|
||||
$profile_type = $this->entityTypeManager->getStorage('profile_type')->load($entity->bundle());
|
||||
$entity->setNewRevision($profile_type->shouldCreateNewRevision());
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
namespace Drupal\profile\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityDeleteForm;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
@@ -12,44 +10,18 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
*/
|
||||
class ProfileTypeDeleteForm extends EntityDeleteForm {
|
||||
|
||||
/**
|
||||
* The query factory to create entity queries.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $queryFactory;
|
||||
|
||||
/**
|
||||
* Constructs a new ProductTypeDeleteForm object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
|
||||
* The entity query object.
|
||||
*/
|
||||
public function __construct(QueryFactory $query_factory) {
|
||||
$this->queryFactory = $query_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.query')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$num_profiles = $this->queryFactory->get('profile')
|
||||
$num_profiles = $this->entityTypeManager->getStorage('profile')->getQuery()
|
||||
->condition('type', $this->entity->id())
|
||||
->count()
|
||||
->execute();
|
||||
if ($num_profiles) {
|
||||
$caption = '<p>' . \Drupal::translation()
|
||||
->formatPlural($num_profiles, '%type is used by 1 profile on your site. You can not remove this profile type until you have removed all of the %type profiles.', '%type is used by @count profiles on your site. You may not remove %type until you have removed all of the %type profiles.', ['%type' => $this->entity->label()]) . '</p>';
|
||||
$form['#title'] = $this->entity->label();
|
||||
$form['#title'] = $this->getQuestion();
|
||||
$form['description'] = ['#markup' => $caption];
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,12 @@ class ProfileTypeForm extends BundleEntityFormBase {
|
||||
'source' => ['label'],
|
||||
],
|
||||
];
|
||||
$form['description'] = [
|
||||
'#title' => $this->t('Description'),
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => $type->getDescription(),
|
||||
'#description' => $this->t('This text will be displayed only for administrative purposes.'),
|
||||
];
|
||||
$form['registration'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Include in user registration form'),
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\profile\Plugin\search_api\processor;
|
||||
|
||||
use Drupal\search_api\IndexInterface;
|
||||
use Drupal\search_api\Processor\ProcessorPluginBase;
|
||||
use Drupal\profile\Entity\ProfileInterface;
|
||||
|
||||
/**
|
||||
* Adds access checks for profiles.
|
||||
*
|
||||
* @SearchApiProcessor(
|
||||
* id = "profile_user_status",
|
||||
* label = @Translation("Profile user status"),
|
||||
* description = @Translation("Adds a check to prevent profiles to be indexed when the owner is not active."),
|
||||
* stages = {
|
||||
* "preprocess_query" = 30,
|
||||
* },
|
||||
* )
|
||||
*/
|
||||
|
||||
class ProfileUserStatus extends ProcessorPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function supportsIndex(IndexInterface $index) {
|
||||
$supported_entity_types = ['profile'];
|
||||
foreach ($index->getDatasources() as $datasource) {
|
||||
if (in_array($datasource->getEntityTypeId(), $supported_entity_types)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function alterIndexedItems(array &$items) {
|
||||
foreach ($items as $item_id => $item) {
|
||||
$object = $item->getOriginalObject()->getValue();
|
||||
if ($object instanceof ProfileInterface) {
|
||||
$user = $object->getOwner();
|
||||
if (!$user->isActive()) {
|
||||
unset($items[$item_id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\profile\Plugin\views\relationship;
|
||||
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\profile\Entity\ProfileType;
|
||||
use Drupal\views\Plugin\views\relationship\RelationshipPluginBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides a views relationship to select profile content by a profile_type.
|
||||
*
|
||||
* @ViewsRelationship("profile_relationship")
|
||||
*/
|
||||
class ProfileViewsRelationship extends RelationshipPluginBase {
|
||||
|
||||
/**
|
||||
* Constructs a ProfileViewsRelationship object.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin_id for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->definition = $plugin_definition + $configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static($configuration, $plugin_id, $plugin_definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
$options['profile_type'] = ['default' => NULL];
|
||||
$options['required'] = ['default' => 1];
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
parent::buildOptionsForm($form, $form_state);
|
||||
|
||||
$form['admin_label']['#description'] = $this->t('The name of the selected profile type makes a good label.');
|
||||
|
||||
$form['profile_type'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('Profile Type'),
|
||||
'#default_value' => $this->options['profile_type'],
|
||||
'#required' => TRUE,
|
||||
];
|
||||
|
||||
foreach (ProfileType::loadMultiple() as $profile_id => $profile_type) {
|
||||
$form['profile_type']['#options'][$profile_id] = $profile_type->label();
|
||||
}
|
||||
|
||||
$form['required']['#description'] .= '<div class="color-warning"><strong>' . $this->t('You must require this relationship to use the Rendered Entity field type for this relationship') . '</strong></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
|
||||
$this->definition['extra'][] = [
|
||||
'field' => 'type',
|
||||
'value' => $this->options['profile_type']
|
||||
];
|
||||
|
||||
parent::query();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Render\RendererInterface;
|
||||
use Drupal\Core\Routing\RedirectDestinationInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
@@ -32,6 +33,13 @@ class ProfileListBuilder extends EntityListBuilder {
|
||||
*/
|
||||
protected $renderer;
|
||||
|
||||
/**
|
||||
* The redirect destination service.
|
||||
*
|
||||
* @var \Drupal\Core\Routing\RedirectDestinationInterface
|
||||
*/
|
||||
protected $redirectDestination;
|
||||
|
||||
/**
|
||||
* Constructs a new ProfileListController object.
|
||||
*
|
||||
@@ -44,11 +52,12 @@ class ProfileListBuilder extends EntityListBuilder {
|
||||
* @param \Drupal\Core\Render\RendererInterface $renderer
|
||||
* The renderer.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatter $date_formatter, RendererInterface $renderer) {
|
||||
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatter $date_formatter, RendererInterface $renderer, RedirectDestinationInterface $redirect_destination) {
|
||||
parent::__construct($entity_type, $storage);
|
||||
|
||||
$this->dateFormatter = $date_formatter;
|
||||
$this->renderer = $renderer;
|
||||
$this->redirectDestination = $redirect_destination;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +68,8 @@ class ProfileListBuilder extends EntityListBuilder {
|
||||
$entity_type,
|
||||
$container->get('entity.manager')->getStorage($entity_type->id()),
|
||||
$container->get('date.formatter'),
|
||||
$container->get('renderer')
|
||||
$container->get('renderer'),
|
||||
$container->get('redirect.destination')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -126,6 +136,11 @@ class ProfileListBuilder extends EntityListBuilder {
|
||||
public function getOperations(EntityInterface $entity) {
|
||||
$operations = parent::getOperations($entity);
|
||||
|
||||
$destination = $this->redirectDestination->getAsArray();
|
||||
foreach ($operations as $key => $operation) {
|
||||
$operations[$key]['query'] = $destination;
|
||||
}
|
||||
|
||||
if ($entity->isActive() && !$entity->isDefault()) {
|
||||
$operations['set_default'] = [
|
||||
'title' => $this->t('Mark as default'),
|
||||
|
||||
@@ -15,6 +15,7 @@ class ProfileTypeListBuilder extends ConfigEntityListBuilder {
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['type'] = $this->t('Profile type');
|
||||
$header['description'] = $this->t('Description');
|
||||
$header['registration'] = $this->t('Registration');
|
||||
$header['multiple'] = $this->t('Allow multiple profiles');
|
||||
return $header + parent::buildHeader();
|
||||
@@ -25,6 +26,7 @@ class ProfileTypeListBuilder extends ConfigEntityListBuilder {
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
$row['type'] = $entity->toLink(NULL, 'edit-form');
|
||||
$row['description'] = $entity->getDescription();
|
||||
$row['registration'] = $entity->getRegistration() ? $this->t('Yes') : $this->t('No');
|
||||
$row['multiple'] = $entity->getMultiple() ? $this->t('Yes') : $this->t('No');
|
||||
return $row + parent::buildRow($entity);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* @endcode
|
||||
* - attributes: HTML attributes for the wrapper.
|
||||
* - profile: The profile object.
|
||||
* - url: The profile URL.
|
||||
* - url: The profile URL, if available.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
|
||||
@@ -5,8 +5,8 @@ description: 'Test module for Profile.'
|
||||
dependencies:
|
||||
- profile
|
||||
|
||||
# Information added by Drupal.org packaging script on 2017-06-12
|
||||
version: '8.x-1.0-beta1'
|
||||
# Information added by Drupal.org packaging script on 2017-09-19
|
||||
version: '8.x-1.0-rc1'
|
||||
core: '8.x'
|
||||
project: 'profile'
|
||||
datestamp: 1497287652
|
||||
datestamp: 1505830148
|
||||
|
||||
@@ -41,6 +41,7 @@ class ProfileTabTest extends ProfileTestBase {
|
||||
'access user profiles',
|
||||
'administer profile',
|
||||
'administer profile types',
|
||||
'administer users',
|
||||
'access administration pages',
|
||||
]);
|
||||
}
|
||||
@@ -87,19 +88,20 @@ class ProfileTabTest extends ProfileTestBase {
|
||||
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
$this->drupalGet('admin/config');
|
||||
$this->clickLink('User profiles');
|
||||
$this->drupalGet('admin/config/people');
|
||||
$this->clickLink('Profile types');
|
||||
$this->assertResponse(200);
|
||||
$this->assertUrl('admin/config/people/profiles');
|
||||
|
||||
$this->drupalGet('admin/people/profiles');
|
||||
$this->assertLink($profile1->label());
|
||||
$this->assertLinkByHref($profile2->toUrl('canonical')->toString());
|
||||
|
||||
$this->drupalGet('admin/people');
|
||||
$tasks = [
|
||||
['entity.user.collection', []],
|
||||
['entity.profile.collection', []],
|
||||
['entity.profile_type.collection', []],
|
||||
];
|
||||
|
||||
$this->assertLocalTasks($tasks, 0);
|
||||
}
|
||||
|
||||
|
||||
+37
-14
@@ -5,6 +5,7 @@ namespace Drupal\Tests\profile\Functional;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\profile\Entity\ProfileType;
|
||||
use Drupal\profile\Entity\Profile;
|
||||
|
||||
/**
|
||||
* Tests basic CRUD functionality of profile types.
|
||||
@@ -35,7 +36,7 @@ class ProfileTypeCRUDTest extends ProfileTestBase {
|
||||
$type = $this->createProfileType($this->randomMachineName());
|
||||
\Drupal::service('router.builder')->rebuildIfNeeded();
|
||||
$this->drupalGet("user/{$this->adminUser->id()}/{$type->id()}");
|
||||
$this->assertResponse(200);
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,11 +46,11 @@ class ProfileTypeCRUDTest extends ProfileTestBase {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Create a new profile type.
|
||||
$this->drupalGet('admin/config/people/profiles/types');
|
||||
$this->assertResponse(200);
|
||||
$this->drupalGet('admin/config/people/profiles');
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
$this->clickLink(t('Add profile type'));
|
||||
|
||||
$this->assertUrl('admin/config/people/profiles/types/add');
|
||||
$this->assertSession()->addressEquals('admin/config/people/profiles/add');
|
||||
$id = Unicode::strtolower($this->randomMachineName());
|
||||
$label = $this->getRandomGenerator()->word(10);
|
||||
$edit = [
|
||||
@@ -57,26 +58,48 @@ class ProfileTypeCRUDTest extends ProfileTestBase {
|
||||
'label' => $label,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertUrl('admin/config/people/profiles/types');
|
||||
$this->assertRaw(new FormattableMarkup('%label profile type has been created.', ['%label' => $label]));
|
||||
$this->assertLinkByHref("admin/config/people/profiles/types/manage/$id");
|
||||
$this->assertLinkByHref("admin/config/people/profiles/types/manage/$id/fields");
|
||||
$this->assertLinkByHref("admin/config/people/profiles/types/manage/$id/display");
|
||||
$this->assertLinkByHref("admin/config/people/profiles/types/manage/$id/delete");
|
||||
$this->assertSession()->addressEquals('admin/config/people/profiles');
|
||||
$this->assertSession()->responseContains(new FormattableMarkup('%label profile type has been created.', ['%label' => $label]));
|
||||
$this->assertSession()->linkByHrefExists("admin/config/people/profiles/manage/$id");
|
||||
$this->assertSession()->linkByHrefExists("admin/config/people/profiles/manage/$id/fields");
|
||||
$this->assertSession()->linkByHrefExists("admin/config/people/profiles/manage/$id/display");
|
||||
$this->assertSession()->linkByHrefExists("admin/config/people/profiles/manage/$id/delete");
|
||||
|
||||
// Edit the new profile type.
|
||||
$this->drupalGet("admin/config/people/profiles/types/manage/$id");
|
||||
$this->assertRaw(new FormattableMarkup('Edit %label profile type', ['%label' => $label]));
|
||||
$this->drupalGet("admin/config/people/profiles/manage/$id");
|
||||
$this->assertSession()->responseContains(new FormattableMarkup('Edit %label profile type', ['%label' => $label]));
|
||||
$this->getSession()->getPage()->checkField('Include in user registration form');
|
||||
$this->getSession()->getPage()->checkField('Create a new revision when a profile is modified');
|
||||
$this->submitForm([], 'Save');
|
||||
$this->assertUrl('admin/config/people/profiles/types');
|
||||
$this->assertRaw(new FormattableMarkup('%label profile type has been updated.', ['%label' => $label]));
|
||||
$this->assertSession()->addressEquals('admin/config/people/profiles');
|
||||
$this->assertSession()->responseContains(new FormattableMarkup('%label profile type has been updated.', ['%label' => $label]));
|
||||
|
||||
$profile_type = ProfileType::load($id);
|
||||
$this->assertEquals($label, $profile_type->label());
|
||||
$this->assertTrue($profile_type->getRegistration());
|
||||
$this->assertTrue($profile_type->shouldCreateNewRevision());
|
||||
|
||||
// Delete profile type.
|
||||
// First check with existing profile of type.
|
||||
$profile = Profile::create([
|
||||
'type' => $id,
|
||||
'uid' => $this->adminUser->id(),
|
||||
]);
|
||||
$profile->save();
|
||||
$this->drupalGet("admin/config/people/profiles/manage/$id/delete");
|
||||
$this->assertSession()->responseContains(new FormattableMarkup('%label is used by 1 profile on your site. You can not remove this profile type until you have removed all of the %label profiles', ['%label' => $label]));
|
||||
|
||||
// Delete profile and delete profile type.
|
||||
$profile->delete();
|
||||
$this->drupalGet("admin/config/people/profiles/manage/$id/delete");
|
||||
$this->assertSession()->responseContains('This action cannot be undone.');
|
||||
$this->assertSession()->linkByHrefExists('admin/config/people/profiles');
|
||||
$this->submitForm([], 'Delete');
|
||||
$this->assertSession()->addressEquals('admin/config/people/profiles');
|
||||
$this->assertSession()->responseContains(new FormattableMarkup('The profile type %label has been deleted.', ['%label' => $label]));
|
||||
|
||||
$profile_type = ProfileType::load($id);
|
||||
$this->assertNull($profile_type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\profile\Functional;
|
||||
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
* Tests basic CRUD functionality of profile types.
|
||||
*
|
||||
* @group profile
|
||||
*/
|
||||
class ProfileTypeTest extends ProfileTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->adminUser = $this->drupalCreateUser([
|
||||
'access user profiles',
|
||||
'administer profile types',
|
||||
'administer profile fields',
|
||||
'administer profile display',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that routes are created for the profile type.
|
||||
*/
|
||||
public function testRoutes() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$type = $this->createProfileType($this->randomMachineName());
|
||||
\Drupal::service('router.builder')->rebuildIfNeeded();
|
||||
$this->drupalGet("user/{$this->adminUser->id()}/{$type->id()}");
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests CRUD operations for profile types through the UI.
|
||||
*/
|
||||
public function testUi() {
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Create a new profile type.
|
||||
$this->drupalGet('admin/config/people/profiles');
|
||||
$this->assertResponse(200);
|
||||
$this->clickLink(t('Add profile type'));
|
||||
|
||||
$this->assertUrl('admin/config/people/profiles/add');
|
||||
$id = Unicode::strtolower($this->randomMachineName());
|
||||
$label = $this->randomString();
|
||||
$edit = [
|
||||
'id' => $id,
|
||||
'label' => $label,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertUrl('admin/config/people/profiles');
|
||||
$this->assertRaw(new FormattableMarkup('%label profile type has been created.', ['%label' => $label]));
|
||||
$this->assertLinkByHref("admin/config/people/profiles/manage/$id");
|
||||
$this->assertLinkByHref("admin/config/people/profiles/manage/$id/fields");
|
||||
$this->assertLinkByHref("admin/config/people/profiles/manage/$id/display");
|
||||
$this->assertLinkByHref("admin/config/people/profiles/manage/$id/delete");
|
||||
|
||||
// Edit the new profile type.
|
||||
$this->drupalGet("admin/config/people/profiles/manage/$id");
|
||||
$this->assertRaw(new FormattableMarkup('Edit %label profile type', ['%label' => $label]));
|
||||
$edit = [
|
||||
'registration' => 1,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertUrl('admin/config/people/profiles');
|
||||
$this->assertRaw(new FormattableMarkup('%label profile type has been updated.', ['%label' => $label]));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -309,8 +309,9 @@ class ProfileTest extends EntityKernelTestBase {
|
||||
$existing_profile_id = $profile2->id();
|
||||
$existing_revision_id = $profile2->getRevisionId();
|
||||
|
||||
// Changing field creates revision.
|
||||
// Changing profiles support revisions.
|
||||
$profile2->get('profile_fullname')->setValue($this->randomMachineName());
|
||||
$profile2->setNewRevision();
|
||||
$profile2->save();
|
||||
|
||||
$profile2 = $this->reloadEntity($profile2);
|
||||
|
||||
Reference in New Issue
Block a user