/**
  * {@inheritdoc}
  */
 protected function alterViewTemplateAfterCreation(array &$view_template, $options = NULL)
 {
     parent::alterViewTemplateAfterCreation($view_template, $options);
     $field_defs = $this->field_manager->getBaseFieldDefinitions($this->getDefinitionValue('entity_type'));
     if (empty($field_defs['status'])) {
         // If entity doesn't have a base field status remove it from View filter.
         unset($view_template['display']['default']['display_options']['filters']['status']);
     }
     $this->field_manager->getFieldDefinitions($this->getDefinitionValue('entity_type'), 'event');
     $this->field_manager->getFieldStorageDefinitions('node');
 }
 /**
  * {@inheritdoc}
  */
 public function onEntityTypeCreate(EntityTypeInterface $entity_type)
 {
     $entity_type_id = $entity_type->id();
     // @todo Forward this to all interested handlers, not only storage, once
     //   iterating handlers is possible: https://www.drupal.org/node/2332857.
     $storage = $this->entityTypeManager->getStorage($entity_type_id);
     if ($storage instanceof EntityTypeListenerInterface) {
         $storage->onEntityTypeCreate($entity_type);
     }
     $this->eventDispatcher->dispatch(EntityTypeEvents::CREATE, new EntityTypeEvent($entity_type));
     $this->entityLastInstalledSchemaRepository->setLastInstalledDefinition($entity_type);
     if ($entity_type->isSubclassOf(FieldableEntityInterface::class)) {
         $this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id, $this->entityFieldManager->getFieldStorageDefinitions($entity_type_id));
     }
 }
 /**
  * Set all derivatives for an entity type.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  * @param array $base_plugin_definition
  */
 protected function setConfigurableFieldsDerivatives(EntityTypeInterface $entity_type, array $base_plugin_definition)
 {
     /** @var \Drupal\Core\Field\FieldStorageDefinitionInterface $field_storage */
     $field_storages = $this->field_manager->getFieldStorageDefinitions($entity_type->id());
     foreach ($field_storages as $field_id => $field_storage) {
         if ($field_storage->getType() == 'datetime') {
             $entity_type_id = $entity_type->id();
             // Find better way to get table name.
             $field_table = $entity_type_id . '__' . $field_id;
             $field_table_data = $this->viewsData->get($field_table);
             if (isset($field_table_data[$field_id])) {
                 $derivative = [];
                 $field_info = $field_table_data[$field_id];
                 $derivative['field_id'] = $field_id;
                 $join_tables = array_keys($field_table_data['table']['join']);
                 // @todo Will there ever be more than 1 tables here?
                 $join_table = array_pop($join_tables);
                 $join_table_data = $this->viewsData->get($join_table);
                 $derivative = ['replacements' => ['field_id' => $field_id, 'entity_type' => $entity_type_id, 'entity_label' => $entity_type->getLabel(), 'field_label' => $field_info['title'], 'base_table' => $join_table, 'field_table' => $field_table, 'default_field_id' => $this->getTableDefaultField($join_table_data, $entity_type_id), 'base_field' => $this->getTableBaseField($join_table_data)], 'view_template_id' => 'calendar_config_field'];
                 $this->setDerivative($derivative, $base_plugin_definition);
                 //$this->setDerivative($field_info, $entity_type, $field_table_data, $base_plugin_definition);
             }
         }
     }
 }
Exemple #4
0
 /**
  * Gets the field storage definition.
  *
  * @return \Drupal\Core\Field\FieldStorageDefinitionInterface
  */
 protected function getFieldStorageDefinition()
 {
     if (empty($this->fieldStorageDefinition)) {
         $field_definitions = $this->entityFieldManager->getFieldStorageDefinitions($this->entityTypeId);
         $this->fieldStorageDefinition = $field_definitions[$this->fieldName];
     }
     return $this->fieldStorageDefinition;
 }
 /**
  * Gets the type of the ID key for a given entity type.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   An entity type.
  *
  * @return string|null
  *   The type of the ID key for a given entity type, or NULL if the entity
  *   type does not support fields.
  */
 protected function getEntityTypeIdKeyType(EntityTypeInterface $entity_type)
 {
     if (!$entity_type->isSubclassOf(FieldableEntityInterface::class)) {
         return NULL;
     }
     $field_storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($entity_type->id());
     return $field_storage_definitions[$entity_type->getKey('id')]->getType();
 }
 /**
  * @covers ::getEntityTypeIdKeyType
  */
 public function testGetEntityTypeIdKeyTypeNotFieldable()
 {
     $entity_type = $this->prophesize(EntityTypeInterface::class);
     $entity_type->isSubclassOf(FieldableEntityInterface::class)->willReturn(FALSE);
     $this->entityFieldManager->getFieldStorageDefinitions(Argument::any())->shouldNotBeCalled();
     $type = $this->routeProvider->getEntityTypeIdKeyType($entity_type->reveal());
     $this->assertNull($type);
 }
 /**
  * Determine if this field is Entity Reference field that references a taxonomy term.
  *
  * @todo Change to a more generic is Content Entity Reference.
  *
  * @param $field_info
  * @param \Drupal\Core\Entity\EntityFieldManagerInterface $field_manager
  */
 protected function isTermReferenceField($field_info, EntityFieldManagerInterface $field_manager) {
   if (!empty($field_info['type']) && $field_info['type'] == 'entity_reference_label') {
     if ($entity_type = $this->getTableEntityType($field_info['table'])) {
       $field_definitions = $field_manager->getFieldStorageDefinitions($entity_type);
       $field_definition = $field_definitions[$field_info['field']];
       $target_type = $field_definition->getSetting('target_type');
       return $target_type == 'taxonomy_term';
     }
   }
   return FALSE;
 }
 /**
  * Checks if a field machine name is taken.
  *
  * @param string $value
  *   The machine name, not prefixed.
  * @param array $element
  *   An array containing the structure of the 'field_name' element.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  *
  * @return bool
  *   Whether or not the field machine name is taken.
  */
 public function fieldNameExists($value, $element, FormStateInterface $form_state)
 {
     // Don't validate the case when an existing field has been selected.
     if ($form_state->getValue('existing_storage_name')) {
         return FALSE;
     }
     // Add the field prefix.
     $field_name = $this->configFactory->get('field_ui.settings')->get('field_prefix') . $value;
     $field_storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($this->entity->getUpdateEntityType());
     return isset($field_storage_definitions[$field_name]);
 }
 /**
  * Utility to determine which view fields can be used for image data.
  *
  * This method will extract a list of fields that can be used as "sources"
  * for a Juicebox gallery along with other useful field information.
  *
  * @return array
  *   An associative array containing a breakdown of field data that can be
  *   referenced by other build methods, including:
  *   - field_options_image: An associative array, keyed by field id, of fields
  *     that can be used as Juicebox gallery image sources.
  *   - field_options_image_type: An associative array, keyed by field id, of
  *     field "types" for all fields listed in 'field_options_image' above.
  *   - field_options: An associative array, keyed by field id, of fields that
  *     cannot be used as Juicebox gallery image sources, but may be useful
  *     for other purposes (text and caption sorces, etc.)
  */
 public function confGetFieldSources()
 {
     $options = array('field_options_images' => array(), 'field_options_images_type' => array(), 'field_options' => array());
     $view = $this->view;
     $field_handlers = $view->display_handler->getHandlers('field');
     $field_labels = $view->display_handler->getFieldLabels();
     // Separate image fields from non-image fields. For image fields we can
     // work with fids and fields of type image or file.
     foreach ($field_handlers as $field => $handler) {
         $is_image = FALSE;
         $id = $handler->getPluginId();
         $name = $field_labels[$field];
         if ($id == 'field') {
             // The field definition is on the handler, it's right bloody there, but
             // it's protected so we can't access it. This means we have to take the
             // long road (via our own injected entity manager) to get the field type
             // info.
             $entity_type = $handler->getEntityType();
             $field_definition = $this->entityFieldManager->getFieldStorageDefinitions($entity_type)[$field];
             $field_type = $field_definition->getType();
             if ($field_type == 'image' || $field_type == 'file') {
                 $field_cardinality = $field_definition->get('cardinality');
                 $options['field_options_images'][$field] = $name . ($field_cardinality == 1 ? '' : '*');
                 $options['field_options_images_type'][$field] = 'file_field';
                 $is_image = TRUE;
             } elseif ($field_type == 'integer' && $field == 'fid') {
                 $options['field_options_images'][$field] = $name;
                 $options['field_options_images_type'][$field] = 'file_id_field';
                 $is_image = TRUE;
             }
         } elseif ($id == 'file' && $field == 'fid') {
             $options['field_options_images'][$field] = $name;
             $options['field_options_images_type'][$field] = 'file_id_field';
             $is_image = TRUE;
         }
         if (!$is_image) {
             $options['field_options'][$field] = $name;
         }
     }
     return $options;
 }
 /**
  * {@inheritdoc}
  */
 public function fieldNameExists($field_name, $entity_type_id)
 {
     $field_storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($entity_type_id);
     return isset($field_storage_definitions[$field_name]);
 }