"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntityDeriver.php" (26 Nov 2020, 1776 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 "ContentEntityDeriver.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Drupal\migrate_drupal\Plugin\migrate\source;
    4 
    5 use Drupal\Component\Plugin\Derivative\DeriverBase;
    6 use Drupal\Core\Entity\ContentEntityTypeInterface;
    7 use Drupal\Core\Entity\EntityTypeManagerInterface;
    8 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
    9 use Symfony\Component\DependencyInjection\ContainerInterface;
   10 
   11 /**
   12  * Deriver for content entity source plugins.
   13  */
   14 class ContentEntityDeriver extends DeriverBase implements ContainerDeriverInterface {
   15 
   16   /**
   17    * The entity type manager.
   18    *
   19    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   20    */
   21   protected $entityTypeManager;
   22 
   23   /**
   24    * Constructs a new ContentEntityDeriver.
   25    *
   26    * @param string $base_plugin_id
   27    *   The base plugin ID.
   28    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   29    *   The entity type manager.
   30    */
   31   public function __construct($base_plugin_id, EntityTypeManagerInterface $entityTypeManager) {
   32     $this->entityTypeManager = $entityTypeManager;
   33   }
   34 
   35   /**
   36    * {@inheritdoc}
   37    */
   38   public static function create(ContainerInterface $container, $base_plugin_id) {
   39     return new static(
   40       $base_plugin_id,
   41       $container->get('entity_type.manager')
   42     );
   43   }
   44 
   45   /**
   46    * {@inheritdoc}
   47    */
   48   public function getDerivativeDefinitions($base_plugin_definition) {
   49     $this->derivatives = [];
   50     foreach ($this->entityTypeManager->getDefinitions() as $id => $definition) {
   51       if ($definition instanceof ContentEntityTypeInterface) {
   52         $this->derivatives[$id] = $base_plugin_definition;
   53         // Provide entity_type so the source can be used apart from a deriver.
   54         $this->derivatives[$id]['entity_type'] = $id;
   55       }
   56     }
   57     return parent::getDerivativeDefinitions($base_plugin_definition);
   58   }
   59 
   60 }