EntityLabel.php in Entity Browser 8.2
File
src/Plugin/EntityBrowser/FieldWidgetDisplay/EntityLabel.php
View source
<?php
namespace Drupal\entity_browser\Plugin\EntityBrowser\FieldWidgetDisplay;
use Drupal\Core\Entity\EntityInterface;
use Drupal\entity_browser\FieldWidgetDisplayBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
class EntityLabel extends FieldWidgetDisplayBase implements ContainerFactoryPluginInterface {
protected $entityRepository;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityRepositoryInterface $entity_repository) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityRepository = $entity_repository;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity.repository'));
}
public function view(EntityInterface $entity) {
$translation = $this->entityRepository
->getTranslationFromContext($entity);
return $translation
->label();
}
public function settingsForm(array $form, FormStateInterface $form_state) {
return [
'#prefix' => '<p>',
'#suffix' => '</p>',
'#markup' => $this
->t('This plugin has no configuration options.'),
];
}
}