use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Session\AccountInterface;
/**
* Plugin implementation of the 'entity_reference' widget for entity browser.
*/
protected $moduleHandler;
+ /**
+ * The current user.
+ *
+ * @var \Drupal\Core\Session\AccountInterface
+ */
+ protected $currentUser;
+
/**
* Constructs widget plugin.
*
* Field widget display plugin manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
+ * @param \Drupal\Core\Session\AccountInterface $current_user
+ * The current user.
*/
- public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityTypeManagerInterface $entity_type_manager, EventDispatcherInterface $event_dispatcher, FieldWidgetDisplayManager $field_display_manager, ModuleHandlerInterface $module_handler) {
+ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityTypeManagerInterface $entity_type_manager, EventDispatcherInterface $event_dispatcher, FieldWidgetDisplayManager $field_display_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
$this->entityTypeManager = $entity_type_manager;
$this->fieldDisplayManager = $field_display_manager;
$this->moduleHandler = $module_handler;
+ $this->currentUser = $current_user;
}
/**
$container->get('entity_type.manager'),
$container->get('event_dispatcher'),
$container->get('plugin.manager.entity_browser.field_widget_display'),
- $container->get('module_handler')
+ $container->get('module_handler'),
+ $container->get('current_user')
);
}
* {@inheritdoc}
*/
public static function defaultSettings() {
- return array(
+ return [
'entity_browser' => NULL,
'open' => FALSE,
'field_widget_display' => 'label',
'field_widget_remove' => TRUE,
'field_widget_display_settings' => [],
'selection_mode' => EntityBrowserElement::SELECTION_MODE_APPEND,
- ) + parent::defaultSettings();
+ ] + parent::defaultSettings();
}
/**
'#default_value' => $this->getSetting('field_widget_display'),
'#options' => $displays,
'#ajax' => [
- 'callback' => array($this, 'updateSettingsAjax'),
+ 'callback' => [$this, 'updateSettingsAjax'],
'wrapper' => $id,
],
];
$this->getSetting('field_widget_display_settings') + ['entity_type' => $this->fieldDefinition->getFieldStorageDefinition()->getSetting('target_type')]
);
+ $classes = ['entities-list'];
+ if ($this->fieldDefinition->getFieldStorageDefinition()->getCardinality() != 1) {
+ $classes[] = 'sortable';
+ }
+
return [
'#theme_wrappers' => ['container'],
- '#attributes' => ['class' => ['entities-list']],
+ '#attributes' => ['class' => $classes],
'items' => array_map(
function (ContentEntityInterface $entity, $row_id) use ($field_widget_display, $details_id, $field_parents) {
$display = $field_widget_display->view($entity);
- $edit_button_access = $this->getSetting('field_widget_edit');
+ $edit_button_access = $this->getSetting('field_widget_edit') && $entity->access('update', $this->currentUser);
if ($entity->getEntityTypeId() == 'file') {
// On file entities, the "edit" button shouldn't be visible unless
// the module "file_entity" is present, which will allow them to be