Namespace
Drupal\exif\Plugin\Field\FieldWidget
File
-
src/Plugin/Field/FieldWidget/ExifReadonlyWidget.php
View source
<?php
namespace Drupal\exif\Plugin\Field\FieldWidget;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ExifReadonlyWidget extends ExifFieldWidgetBase implements ContainerFactoryPluginInterface {
protected $entityTypeManager;
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['third_party_settings'], $container->get('entity_type.manager'));
}
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$value = $items->getValue();
$entity_type = $items->getFieldDefinition()
->getTargetEntityTypeId();
$access = $this->entityTypeManager
->getAccessControlHandler($entity_type)
->fieldAccess('view', $items->getFieldDefinition());
if (!$access) {
$element += [
'#type' => '#hidden',
'#value' => '',
];
}
$element += $items->view();
$element += [
'#value' => $value,
'#default_value' => $value,
];
return $element;
}
}
Classes
| Title |
Deprecated |
Summary |
| ExifReadonlyWidget |
|
Plugin implementation of the 'exif_readonly' widget. |