annotate core/modules/views/src/Plugin/Derivative/ViewsEntityRow.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\views\Plugin\Derivative;
Chris@0 4
Chris@0 5 use Drupal\Core\Entity\EntityManagerInterface;
Chris@0 6 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
Chris@0 7 use Drupal\views\ViewsData;
Chris@0 8 use Symfony\Component\DependencyInjection\ContainerInterface;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Provides views row plugin definitions for all non-special entity types.
Chris@0 12 *
Chris@0 13 * @ingroup views_row_plugins
Chris@0 14 *
Chris@0 15 * @see \Drupal\views\Plugin\views\row\EntityRow
Chris@0 16 */
Chris@0 17 class ViewsEntityRow implements ContainerDeriverInterface {
Chris@0 18
Chris@0 19 /**
Chris@0 20 * Stores all entity row plugin information.
Chris@0 21 *
Chris@0 22 * @var array
Chris@0 23 */
Chris@0 24 protected $derivatives = [];
Chris@0 25
Chris@0 26 /**
Chris@0 27 * The base plugin ID that the derivative is for.
Chris@0 28 *
Chris@0 29 * @var string
Chris@0 30 */
Chris@0 31 protected $basePluginId;
Chris@0 32
Chris@0 33 /**
Chris@0 34 * The entity manager.
Chris@0 35 *
Chris@0 36 * @var \Drupal\Core\Entity\EntityManagerInterface
Chris@0 37 */
Chris@0 38 protected $entityManager;
Chris@0 39
Chris@0 40 /**
Chris@0 41 * The views data service.
Chris@0 42 *
Chris@0 43 * @var \Drupal\views\ViewsData
Chris@0 44 */
Chris@0 45 protected $viewsData;
Chris@0 46
Chris@0 47 /**
Chris@0 48 * Constructs a ViewsEntityRow object.
Chris@0 49 *
Chris@0 50 * @param string $base_plugin_id
Chris@0 51 * The base plugin ID.
Chris@0 52 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
Chris@0 53 * The entity manager.
Chris@0 54 * @param \Drupal\views\ViewsData $views_data
Chris@0 55 * The views data service.
Chris@0 56 */
Chris@0 57 public function __construct($base_plugin_id, EntityManagerInterface $entity_manager, ViewsData $views_data) {
Chris@0 58 $this->basePluginId = $base_plugin_id;
Chris@0 59 $this->entityManager = $entity_manager;
Chris@0 60 $this->viewsData = $views_data;
Chris@0 61 }
Chris@0 62
Chris@0 63 /**
Chris@0 64 * {@inheritdoc}
Chris@0 65 */
Chris@0 66 public static function create(ContainerInterface $container, $base_plugin_id) {
Chris@0 67 return new static(
Chris@0 68 $base_plugin_id,
Chris@0 69 $container->get('entity.manager'),
Chris@0 70 $container->get('views.views_data')
Chris@0 71 );
Chris@0 72 }
Chris@0 73
Chris@0 74 /**
Chris@0 75 * {@inheritdoc}
Chris@0 76 */
Chris@0 77 public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
Chris@0 78 if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
Chris@0 79 return $this->derivatives[$derivative_id];
Chris@0 80 }
Chris@0 81 $this->getDerivativeDefinitions($base_plugin_definition);
Chris@0 82 return $this->derivatives[$derivative_id];
Chris@0 83 }
Chris@0 84
Chris@0 85 /**
Chris@0 86 * {@inheritdoc}
Chris@0 87 */
Chris@0 88 public function getDerivativeDefinitions($base_plugin_definition) {
Chris@0 89 foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
Chris@0 90 // Just add support for entity types which have a views integration.
Chris@0 91 if (($base_table = $entity_type->getBaseTable()) && $this->viewsData->get($base_table) && $this->entityManager->hasHandler($entity_type_id, 'view_builder')) {
Chris@0 92 $this->derivatives[$entity_type_id] = [
Chris@0 93 'id' => 'entity:' . $entity_type_id,
Chris@0 94 'provider' => 'views',
Chris@0 95 'title' => $entity_type->getLabel(),
Chris@0 96 'help' => t('Display the @label', ['@label' => $entity_type->getLabel()]),
Chris@0 97 'base' => [$entity_type->getDataTable() ?: $entity_type->getBaseTable()],
Chris@0 98 'entity_type' => $entity_type_id,
Chris@0 99 'display_types' => ['normal'],
Chris@0 100 'class' => $base_plugin_definition['class'],
Chris@0 101 ];
Chris@0 102 }
Chris@0 103 }
Chris@0 104
Chris@0 105 return $this->derivatives;
Chris@0 106 }
Chris@0 107
Chris@0 108 }