/**
  * Returns an array of applicable widget or formatter options for a field.
  *
  * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
  *   The field definition.
  *
  * @return array
  *   An array of applicable widget or formatter options.
  */
 protected function getApplicablePluginOptions(FieldDefinitionInterface $field_definition)
 {
     $options = $this->pluginManager->getOptions($field_definition->getType());
     $applicable_options = array();
     foreach ($options as $option => $label) {
         $plugin_class = DefaultFactory::getPluginClass($option, $this->pluginManager->getDefinition($option));
         if ($plugin_class::isApplicable($field_definition)) {
             $applicable_options[$option] = $label;
         }
     }
     return $applicable_options;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function onDependencyRemoval(array $dependencies)
 {
     $changed = parent::onDependencyRemoval($dependencies);
     foreach ($dependencies['config'] as $entity) {
         if ($entity->getEntityTypeId() == 'field_config') {
             // Remove components for fields that are being deleted.
             $this->removeComponent($entity->getName());
             unset($this->hidden[$entity->getName()]);
             $changed = TRUE;
         }
     }
     foreach ($this->getComponents() as $name => $component) {
         if (isset($component['type']) && ($definition = $this->pluginManager->getDefinition($component['type'], FALSE))) {
             if (in_array($definition['provider'], $dependencies['module'])) {
                 // Revert to the defaults if the plugin that supplies the widget or
                 // formatter depends on a module that is being uninstalled.
                 $this->setComponent($name);
                 $changed = TRUE;
             }
         }
     }
     return $changed;
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     parent::calculateDependencies();
     $target_entity_type = \Drupal::entityManager()->getDefinition($this->targetEntityType);
     $bundle_entity_type_id = $target_entity_type->getBundleEntityType();
     if ($bundle_entity_type_id != 'bundle') {
         // If the target entity type uses entities to manage its bundles then
         // depend on the bundle entity.
         $bundle_entity = \Drupal::entityManager()->getStorage($bundle_entity_type_id)->load($this->bundle);
         $this->addDependency('entity', $bundle_entity->getConfigDependencyName());
     } else {
         // Depend on the provider of the entity type.
         $this->addDependency('module', $target_entity_type->getProvider());
     }
     // Create dependencies on both hidden and visible fields.
     $fields = $this->content + $this->hidden;
     foreach ($fields as $field_name => $component) {
         $field_instance = FieldInstanceConfig::loadByName($this->targetEntityType, $this->bundle, $field_name);
         if ($field_instance) {
             $this->addDependency('entity', $field_instance->getConfigDependencyName());
         }
         // Create a dependency on the module that provides the formatter or
         // widget.
         if (isset($component['type']) && ($definition = $this->pluginManager->getDefinition($component['type'], FALSE))) {
             $this->addDependency('module', $definition['provider']);
         }
         // Create dependencies on any modules providing third party settings.
         if (isset($component['third_party_settings'])) {
             foreach ($component['third_party_settings'] as $module => $settings) {
                 $this->addDependency('module', $module);
             }
         }
     }
     // Depend on configured modes.
     if ($this->mode != 'default') {
         $mode_entity = \Drupal::entityManager()->getStorage($this->displayContext . '_mode')->load($target_entity_type->id() . '.' . $this->mode);
         $this->addDependency('entity', $mode_entity->getConfigDependencyName());
     }
     return $this->dependencies;
 }