updated contrib modules
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user