Example #1
0
 /**
  * Discovers all fields/properties of an entity.
  *
  * @param \Drupal\feeds\ImporterInterface $importer
  *   The importer.
  */
 protected static function buildProperties(EntityProcessor $processor)
 {
     $entity_type = $processor->entityType();
     $info = \Drupal::entityManager()->getDefinition($entity_type);
     $bundle_key = NULL;
     if (isset($info['entity_keys']['bundle'])) {
         $bundle_key = $info['entity_keys']['bundle'];
     }
     $field_definitions = \Drupal::entityManager()->getFieldDefinitions($entity_type, $processor->bundle());
     foreach ($field_definitions as $id => $field_definition) {
         if ($field_definition->isReadOnly() || $id == $bundle_key) {
             continue;
         }
         static::$properties[$id] = $field_definition->getItemDefinition()->toArray();
         static::$properties[$id]['label'] = $field_definition->getLabel();
         static::$properties[$id]['description'] = $field_definition->getDescription();
         static::$properties[$id]['settings'] = $field_definition->getSettings();
         foreach (\Drupal::typedData()->create($field_definition->getItemDefinition())->getPropertyDefinitions() as $property => $data_definition) {
             if (!$data_definition->isComputed()) {
                 static::$properties[$id]['properties'][$property] = $data_definition->toArray();
             }
         }
         $instance_id = $entity_type . '.' . $processor->bundle() . '.' . $id;
         $instance = \Drupal::entityManager()->getStorageController('field_instance')->load($instance_id);
         if ($instance) {
             static::$properties[$id]['label'] = $instance->getLabel();
             static::$properties[$id]['description'] = $instance->getDescription();
             static::$properties[$id]['settings'] = $instance->getSettings();
         }
     }
 }