/** * Constructs a new FieldStorageConfigListBuilder object. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager * The 'field type' plugin manager. */ public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, EntityTypeBundleInfoInterface $bundle_info_service) { parent::__construct($entity_type, $entity_manager->getStorage($entity_type->id())); $this->entityManager = $entity_manager; $this->bundles = $bundle_info_service->getAllBundleInfo(); $this->fieldTypeManager = $field_type_manager; $this->fieldTypes = $this->fieldTypeManager->getDefinitions(); }
/** * Constructs a new FieldStorageConfigListBuilder object. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager * The 'field type' plugin manager. */ public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager) { parent::__construct($entity_type, $entity_manager->getStorage($entity_type->id())); $this->entityManager = $entity_manager; $this->bundles = entity_get_bundles(); $this->fieldTypeManager = $field_type_manager; $this->fieldTypes = $this->fieldTypeManager->getDefinitions(); }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->fieldTypePluginManager->getDefinitions() as $plugin_id => $definition) { $definition['definition_class'] = '\\Drupal\\Core\\Field\\TypedData\\FieldItemDataDefinition'; $definition['list_definition_class'] = '\\Drupal\\Core\\Field\\FieldDefinition'; $this->derivatives[$plugin_id] = $definition; } return $this->derivatives; }
/** * Returns an array of existing fields to be added to a bundle. * * @return array * An array of existing fields keyed by field name. */ protected function getExistingFieldOptions() { $options = array(); // Collect candidate field instances: all instances of fields for this // entity type that are not already present in the current bundle. $field_map = \Drupal::entityManager()->getFieldMap(); $instance_ids = array(); if (!empty($field_map[$this->entity_type])) { foreach ($field_map[$this->entity_type] as $field_name => $data) { if (!in_array($this->bundle, $data['bundles'])) { $bundle = reset($data['bundles']); $instance_ids[] = $this->entity_type . '.' . $bundle . '.' . $field_name; } } } // Load the instances and build the list of options. if ($instance_ids) { $field_types = $this->fieldTypeManager->getDefinitions(); $instances = $this->entityManager->getStorage('field_instance_config')->loadMultiple($instance_ids); foreach ($instances as $instance) { // Do not show: // - locked fields, // - fields that should not be added via user interface. $field_type = $instance->getType(); $field_storage = $instance->getFieldStorageDefinition(); if (empty($field_storage->locked) && empty($field_types[$field_type]['no_ui'])) { $options[$instance->getName()] = array('type' => $field_type, 'type_label' => $field_types[$field_type]['label'], 'field' => $instance->getName(), 'label' => $instance->getLabel()); } } } return $options; }
/** * Constructs a new DisplayOverviewBase. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager * The field type manager. * @param \Drupal\Component\Plugin\PluginManagerBase $plugin_manager * The widget or formatter plugin manager. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The configuration factory. */ public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, PluginManagerBase $plugin_manager, ConfigFactoryInterface $config_factory) { parent::__construct($entity_manager); $this->fieldTypes = $field_type_manager->getDefinitions(); $this->pluginManager = $plugin_manager; $this->configFactory = $config_factory; }
/** * {@inheritdoc} */ public function buildRow(EntityInterface $field_config) { /** @var \Drupal\field\FieldConfigInterface $field_config */ $field_storage = $field_config->getFieldStorageDefinition(); $route_parameters = array('field_config' => $field_config->id()) + FieldUI::getRouteBundleParameter($this->entityManager->getDefinition($this->targetEntityTypeId), $this->targetBundle); $row = array('id' => Html::getClass($field_config->getName()), 'data' => array('label' => $field_config->getLabel(), 'field_name' => $field_config->getName(), 'field_type' => array('data' => array('#type' => 'link', '#title' => $this->fieldTypeManager->getDefinitions()[$field_storage->getType()]['label'], '#url' => Url::fromRoute("entity.field_config.{$this->targetEntityTypeId}_storage_edit_form", $route_parameters), '#options' => array('attributes' => array('title' => $this->t('Edit field settings.'))))))); // Add the operations. $row['data'] = $row['data'] + parent::buildRow($field_config); if ($field_storage->isLocked()) { $row['data']['operations'] = array('data' => array('#markup' => $this->t('Locked'))); $row['class'][] = 'menu-disabled'; } return $row; }
/** * Returns an array of existing field storages that can be added to a bundle. * * @return array * An array of existing field storages keyed by name. */ protected function getExistingFieldStorageOptions() { $options = array(); // Load the field_storages and build the list of options. $field_types = $this->fieldTypePluginManager->getDefinitions(); foreach ($this->entityManager->getFieldStorageDefinitions($this->entityTypeId) as $field_name => $field_storage) { // Do not show: // - non-configurable field storages, // - locked field storages, // - field storages that should not be added via user interface, // - field storages that already have a field in the bundle. $field_type = $field_storage->getType(); if ($field_storage instanceof FieldStorageConfigInterface && !$field_storage->isLocked() && empty($field_types[$field_type]['no_ui']) && !in_array($this->bundle, $field_storage->getBundles(), TRUE)) { $options[$field_name] = $this->t('@type: @field', array('@type' => $field_types[$field_type]['label'], '@field' => $field_name)); } } asort($options); return $options; }
/** * Returns an array of widget type options for a field type. * * @param string|null $field_type * (optional) The name of a field type, or NULL to retrieve all widget * options. Defaults to NULL. * * @return array * If no field type is provided, returns a nested array of all widget types, * keyed by field type human name. */ public function getOptions($field_type = NULL) { if (!isset($this->widgetOptions)) { $options = array(); $field_types = $this->fieldTypeManager->getDefinitions(); $widget_types = $this->getDefinitions(); uasort($widget_types, array('Drupal\\Component\\Utility\\SortArray', 'sortByWeightElement')); foreach ($widget_types as $name => $widget_type) { foreach ($widget_type['field_types'] as $widget_field_type) { // Check that the field type exists. if (isset($field_types[$widget_field_type])) { $options[$widget_field_type][$name] = $widget_type['label']; } } } $this->widgetOptions = $options; } if (isset($field_type)) { return !empty($this->widgetOptions[$field_type]) ? $this->widgetOptions[$field_type] : array(); } return $this->widgetOptions; }
/** * Constructs a new EntityDisplayFormBase. * * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager * The field type manager. * @param \Drupal\Component\Plugin\PluginManagerBase $plugin_manager * The widget or formatter plugin manager. */ public function __construct(FieldTypePluginManagerInterface $field_type_manager, PluginManagerBase $plugin_manager) { $this->fieldTypes = $field_type_manager->getDefinitions(); $this->pluginManager = $plugin_manager; }
/** * Returns the label for a specified field type. * * @param string $field_type * The field type. * * @return string * The field type label. */ protected function getFieldTypeLabel($field_type) { return $this->fieldTypeManager->getDefinitions()[$field_type]['label']; }