/**
  * 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;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function setComponent($name, array $options = array())
 {
     // If no weight specified, make sure the field sinks at the bottom.
     if (!isset($options['weight'])) {
         $max = $this->getHighestWeight();
         $options['weight'] = isset($max) ? $max + 1 : 0;
     }
     // For a field, fill in default options.
     if ($field_definition = $this->getFieldDefinition($name)) {
         $options = $this->pluginManager->prepareConfiguration($field_definition->getType(), $options);
     }
     // Ensure we always have an empty settings and array.
     $options += ['settings' => [], 'third_party_settings' => []];
     $this->content[$name] = $options;
     unset($this->hidden[$name]);
     unset($this->plugins[$name]);
     return $this;
 }
Example #3
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;
 }
 /**
  * Returns an array of widget or formatter options for a field type.
  *
  * @param string $field_type
  *   The name of the field type.
  *
  * @return array
  *   An array of widget or formatter options.
  */
 protected function getPluginOptions($field_type)
 {
     return $this->pluginManager->getOptions($field_type);
 }