"Fossies" - the Fresh Open Source Software Archive

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

    1 <?php
    2 
    3 namespace Drupal\migrate;
    4 
    5 /**
    6  * The entity field definition trait.
    7  */
    8 trait EntityFieldDefinitionTrait {
    9 
   10   /**
   11    * Gets the field definition from a specific entity base field.
   12    *
   13    * The method takes the field ID as an argument and returns the field storage
   14    * definition to be used in getIds() by querying the destination entity base
   15    * field definition.
   16    *
   17    * @param string $key
   18    *   The field ID key.
   19    *
   20    * @return array
   21    *   An associative array with a structure that contains the field type, keyed
   22    *   as 'type', together with field storage settings as they are returned by
   23    *   FieldStorageDefinitionInterface::getSettings().
   24    *
   25    * @see \Drupal\Core\Field\FieldStorageDefinitionInterface::getSettings()
   26    */
   27   protected function getDefinitionFromEntity($key) {
   28     $plugin_id = $this->getPluginId();
   29     $entity_type_id = $this->getEntityTypeId($plugin_id);
   30     /** @var \Drupal\Core\Field\FieldStorageDefinitionInterface[] $definitions */
   31     $definitions = $this->entityFieldManager->getBaseFieldDefinitions($entity_type_id);
   32     $field_definition = $definitions[$key];
   33 
   34     return [
   35       'type' => $field_definition->getType(),
   36     ] + $field_definition->getSettings();
   37   }
   38 
   39   /**
   40    * Finds the entity type from configuration or plugin ID.
   41    *
   42    * @param string $plugin_id
   43    *   The plugin ID.
   44    *
   45    * @return string
   46    *   The entity type.
   47    */
   48   protected static function getEntityTypeId($plugin_id) {
   49     $entity_type_id = NULL;
   50     if (strpos($plugin_id, static::DERIVATIVE_SEPARATOR)) {
   51       list(, $entity_type_id) = explode(static::DERIVATIVE_SEPARATOR, $plugin_id, 2);
   52     }
   53     return $entity_type_id;
   54   }
   55 
   56 }