"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/modules/views/src/Plugin/Derivative/ViewsEntityRow.php" (26 Nov 2020, 3346 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ViewsEntityRow.php" see the Fossies "Dox" file reference documentation.

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