Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getEditor($formatter_type, FieldItemListInterface $items)
 {
     // Check if the formatter defines an appropriate in-place editor. For
     // example, text formatters displaying plain text can choose to use the
     // 'plain_text' editor. If the formatter doesn't specify, fall back to the
     // 'form' editor, since that can work for any field. Formatter definitions
     // can use 'disabled' to explicitly opt out of in-place editing.
     $formatter_info = $this->formatterManager->getDefinition($formatter_type);
     $editor_id = $formatter_info['quickedit']['editor'];
     if ($editor_id === 'disabled') {
         return;
     } elseif ($editor_id === 'form') {
         return 'form';
     }
     // No early return, so create a list of all choices.
     $editor_choices = array($editor_id);
     if (isset($this->alternatives[$editor_id])) {
         $editor_choices = array_merge($editor_choices, $this->alternatives[$editor_id]);
     }
     // Make a choice.
     foreach ($editor_choices as $editor_id) {
         $editor = $this->editorManager->createInstance($editor_id);
         if ($editor->isCompatible($items)) {
             return $editor_id;
         }
     }
     // We still don't have a choice, so fall back to the default 'form' editor.
     return 'form';
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  *
  * @throws \LogicException
  *   Throws an exception if field type is not defined in the annotation of the
  *   Entity Embed Display plugin.
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     // The field type must be defined in the annotation of the Entity Embed
     // Display plugin.
     if (!isset($base_plugin_definition['field_type'])) {
         throw new \LogicException("Undefined field_type definition in plugin {$base_plugin_definition['id']}.");
     }
     foreach ($this->formatterManager->getOptions($base_plugin_definition['field_type']) as $formatter => $label) {
         $this->derivatives[$formatter] = $base_plugin_definition;
         $this->derivatives[$formatter]['label'] = $label;
     }
     return $this->derivatives;
 }