Commit 0959ae04 authored by webchick's avatar webchick

Issue #2144879 by Wim Leers, yched: Brush up...

Issue #2144879 by Wim Leers, yched: Brush up MetadataGeneratorInterface::generate(Field|Entity)(): use FieldItemListInterface + better naming.
parent 09d4cc93
......@@ -161,14 +161,15 @@ public function metadata(Request $request) {
throw new NotFoundHttpException();
}
$entity = $entity->getTranslation($langcode);
// If the entity information for this field is requested, include it.
$entity_id = $entity->entityType() . '/' . $entity_id;
if (is_array($entities) && in_array($entity_id, $entities) && !isset($metadata[$entity_id])) {
$metadata[$entity_id] = $this->metadataGenerator->generateEntity($entity, $langcode);
$metadata[$entity_id] = $this->metadataGenerator->generateEntityMetadata($entity);
}
$field_definition = $entity->get($field_name)->getFieldDefinition();
$metadata[$field] = $this->metadataGenerator->generateField($entity, $field_definition, $langcode, $view_mode);
$metadata[$field] = $this->metadataGenerator->generateFieldMetadata($entity->get($field_name), $view_mode);
}
return new JsonResponse($metadata);
......
......@@ -8,7 +8,7 @@
namespace Drupal\edit;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
/**
* Defines an interface for in-place editors plugins.
......@@ -16,17 +16,15 @@
interface EditPluginInterface extends PluginInspectionInterface {
/**
* Checks whether this editor is compatible with a given field instance.
* Checks whether this in-place editor is compatible with a given field.
*
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
* The field definition of the field being edited.
* @param array $items
* The field's item values.
* @param \Drupal\Core\Field\FieldItemListInterface $items
* The field values to be in-place edited.
*
* @return bool
* TRUE if it is compatible, FALSE otherwise.
*/
public function isCompatible(FieldDefinitionInterface $field_definition, array $items);
public function isCompatible(FieldItemListInterface $items);
/**
* Generates metadata that is needed specifically for this editor.
......@@ -34,16 +32,14 @@ public function isCompatible(FieldDefinitionInterface $field_definition, array $
* Will only be called by \Drupal\edit\MetadataGeneratorInterface::generate()
* when the passed in field instance & item values will use this editor.
*
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
* The field definition of the field being edited.
* @param array $items
* The field's item values.
* @param \Drupal\Core\Field\FieldItemListInterface $items
* The field values to be in-place edited.
*
* @return array
* A keyed array with metadata. Each key should be prefixed with the plugin
* ID of the editor.
*/
public function getMetadata(FieldDefinitionInterface $field_definition, array $items);
public function getMetadata(FieldItemListInterface $items);
/**
* Returns the attachments for this editor.
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Plugin\PluginBase;
use Drupal\edit\EditPluginInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
/**
* Defines a base editor implementation.
......@@ -19,7 +19,7 @@ abstract class EditorBase extends PluginBase implements EditPluginInterface {
/**
* {@inheritdoc}
*/
function getMetadata(FieldDefinitionInterface $field_definition, array $items) {
function getMetadata(FieldItemListInterface $items) {
return array();
}
......
......@@ -9,7 +9,7 @@
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterPluginManager;
/**
......@@ -54,7 +54,7 @@ public function __construct(PluginManagerInterface $editor_manager, FormatterPlu
/**
* {@inheritdoc}
*/
public function getEditor($formatter_type, FieldDefinitionInterface $field_definition, array $items) {
public function getEditor($formatter_type, FieldItemListInterface $items) {
// Build a static cache of the editors that have registered themselves as
// alternatives to a certain editor.
if (!isset($this->alternatives)) {
......@@ -91,7 +91,7 @@ public function getEditor($formatter_type, FieldDefinitionInterface $field_defin
// Make a choice.
foreach ($editor_choices as $editor_id) {
$editor = $this->editorManager->createInstance($editor_id);
if ($editor->isCompatible($field_definition, $items)) {
if ($editor->isCompatible($items)) {
return $editor_id;
}
}
......
......@@ -7,7 +7,7 @@
namespace Drupal\edit;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
/**
* Interface for selecting an in-place editor (an Editor plugin) for a field.
......@@ -19,15 +19,13 @@ interface EditorSelectorInterface {
*
* @param string $formatter_type
* The field's formatter type name.
* @param \Drupal\Core\Field\FieldDefinitionInterface $instance
* The field definition.
* @param array $items
* The field's item values.
* @param \Drupal\Core\Field\FieldItemListInterface $items
* The field values to be in-place edited.
*
* @return string|null
* The editor to use, or NULL to not enable in-place editing.
*/
public function getEditor($formatter_type, FieldDefinitionInterface $instance, array $items);
public function getEditor($formatter_type, FieldItemListInterface $items);
/**
* Returns the attachments for all editors.
......
......@@ -7,9 +7,9 @@
namespace Drupal\edit;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\edit\Access\EditEntityFieldAccessCheckInterface;
use Drupal\field\FieldInstanceInterface;
......@@ -58,17 +58,18 @@ public function __construct(EditEntityFieldAccessCheckInterface $access_checker,
/**
* {@inheritdoc}
*/
public function generateEntity(EntityInterface $entity, $langcode) {
public function generateEntityMetadata(EntityInterface $entity) {
return array(
'label' => $entity->label($langcode),
'label' => $entity->label(),
);
}
/**
* {@inheritdoc}
*/
public function generateField(EntityInterface $entity, FieldDefinitionInterface $field_definition, $langcode, $view_mode) {
$field_name = $field_definition->getName();
public function generateFieldMetadata(FieldItemListInterface $items, $view_mode) {
$entity = $items->getEntity();
$field_name = $items->getFieldDefinition()->getName();
// Early-return if user does not have access.
$access = $this->accessChecker->accessEditEntityField($entity, $field_name);
......@@ -78,14 +79,13 @@ public function generateField(EntityInterface $entity, FieldDefinitionInterface
// Early-return if no editor is available.
$formatter_id = entity_get_render_display($entity, $view_mode)->getRenderer($field_name)->getPluginId();
$items = $entity->getTranslation($langcode)->get($field_name)->getValue();
$editor_id = $this->editorSelector->getEditor($formatter_id, $field_definition, $items);
$editor_id = $this->editorSelector->getEditor($formatter_id, $items);
if (!isset($editor_id)) {
return array('access' => FALSE);
}
// Gather metadata, allow the editor to add additional metadata of its own.
$label = $field_definition->getLabel();
$label = $items->getFieldDefinition()->getLabel();
$editor = $this->editorManager->createInstance($editor_id);
$metadata = array(
'label' => check_plain($label),
......@@ -93,7 +93,7 @@ public function generateField(EntityInterface $entity, FieldDefinitionInterface
'editor' => $editor_id,
'aria' => t('Entity @type @id, field @field', array('@type' => $entity->entityType(), '@id' => $entity->id(), '@field' => $label)),
);
$custom_metadata = $editor->getMetadata($field_definition, $items);
$custom_metadata = $editor->getMetadata($items);
if (count($custom_metadata)) {
$metadata['custom'] = $custom_metadata;
}
......
......@@ -8,7 +8,7 @@
namespace Drupal\edit;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
/**
* Interface for generating in-place editing metadata.
......@@ -19,24 +19,18 @@ interface MetadataGeneratorInterface {
* Generates in-place editing metadata for an entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being edited.
* @param string $langcode
* The name of the language for which the field is being edited.
* The entity, in the language in which one of its fields is being edited.
* @return array
* An array containing metadata with the following keys:
* - label: the user-visible label for the entity in the given language.
*/
public function generateEntity(EntityInterface $entity, $langcode);
public function generateEntityMetadata(EntityInterface $entity);
/**
* Generates in-place editing metadata for an entity field.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being edited.
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
* The field definition of the field being edited.
* @param string $langcode
* The name of the language for which the field is being edited.
* @param \Drupal\Core\Field\FieldItemListInterface $items
* The field values to be in-place edited.
* @param string $view_mode
* The view mode the field should be rerendered in.
* @return array
......@@ -47,6 +41,6 @@ public function generateEntity(EntityInterface $entity, $langcode);
* - aria: the ARIA label.
* - custom: (optional) any additional metadata that the editor provides.
*/
public function generateField(EntityInterface $entity, FieldDefinitionInterface $field_definition, $langcode, $view_mode);
public function generateFieldMetadata(FieldItemListInterface $items, $view_mode);
}
......@@ -7,8 +7,8 @@
namespace Drupal\edit\Plugin\InPlaceEditor;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\edit\EditorBase;
use Drupal\Core\Field\FieldDefinitionInterface;
/**
* Defines the form in-place editor.
......@@ -22,7 +22,7 @@ class FormEditor extends EditorBase {
/**
* {@inheritdoc}
*/
function isCompatible(FieldDefinitionInterface $field_definition, array $items) {
public function isCompatible(FieldItemListInterface $items) {
return TRUE;
}
......
......@@ -7,8 +7,8 @@
namespace Drupal\edit\Plugin\InPlaceEditor;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\edit\EditorBase;
use Drupal\Core\Field\FieldDefinitionInterface;
/**
* Defines the plain text in-place editor.
......@@ -25,7 +25,9 @@ class PlainTextEditor extends EditorBase {
* @todo The processed text logic is too coupled to text fields. Figure out
* how to generalize to other textual field types.
*/
function isCompatible(FieldDefinitionInterface $field_definition, array $items) {
public function isCompatible(FieldItemListInterface $items) {
$field_definition = $items->getFieldDefinition();
// This editor is incompatible with multivalued fields.
if ($field_definition->getCardinality() != 1) {
return FALSE;
......
......@@ -7,6 +7,7 @@
namespace Drupal\edit\Tests;
use Drupal\Core\Language\Language;
use Drupal\edit\Plugin\InPlaceEditorManager;
use Drupal\edit\EditorSelector;
......@@ -45,13 +46,13 @@ protected function setUp() {
}
/**
* Retrieves the FieldInstance object for the given field and returns the
* editor that Edit selects.
* Returns the in-place editor that Edit selects.
*/
protected function getSelectedEditor($items, $field_name, $view_mode = 'default') {
protected function getSelectedEditor($entity_id, $field_name, $view_mode = 'default') {
$entity = entity_load('entity_test', $entity_id, TRUE);
$items = $entity->getTranslation(Language::LANGCODE_NOT_SPECIFIED)->get($field_name);
$options = entity_get_display('entity_test', 'entity_test', $view_mode)->getComponent($field_name);
$field_instance = field_info_instance('entity_test', $field_name, 'entity_test');
return $this->editorSelector->getEditor($options['type'], $field_instance, $items);
return $this->editorSelector->getEditor($options['type'], $items);
}
/**
......@@ -72,32 +73,34 @@ public function testText() {
array()
);
// Pretend there is an entity with these items for the field.
$items = array(array('value' => 'Hello, world!', 'format' => 'full_html'));
// Create an entity with values for this text field.
$this->entity = entity_create('entity_test', array());
$this->entity->{$field_name}->value = 'Hello, world!';
$this->entity->{$field_name}->format = 'full_html';
$this->entity->save();
// Editor selection without text processing, with cardinality 1.
$this->assertEqual('plain_text', $this->getSelectedEditor($items, $field_name), "Without text processing, cardinality 1, the 'plain_text' editor is selected.");
$this->assertEqual('plain_text', $this->getSelectedEditor($this->entity->id(), $field_name), "Without text processing, cardinality 1, the 'plain_text' editor is selected.");
// Editor selection with text processing, cardinality 1.
$this->field_text_instance->settings['text_processing'] = 1;
$this->field_text_instance->save();
$this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "With text processing, cardinality 1, the 'form' editor is selected.");
$this->assertEqual('form', $this->getSelectedEditor($this->entity->id(), $field_name), "With text processing, cardinality 1, the 'form' editor is selected.");
// Editor selection without text processing, cardinality 1 (again).
$this->field_text_instance->settings['text_processing'] = 0;
$this->field_text_instance->save();
$this->assertEqual('plain_text', $this->getSelectedEditor($items, $field_name), "Without text processing again, cardinality 1, the 'plain_text' editor is selected.");
$this->assertEqual('plain_text', $this->getSelectedEditor($this->entity->id(), $field_name), "Without text processing again, cardinality 1, the 'plain_text' editor is selected.");
// Editor selection without text processing, cardinality >1
$this->field_text_field->cardinality = 2;
$this->field_text_field->save();
$items[] = array('value' => 'Hallo, wereld!', 'format' => 'full_html');
$this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "Without text processing, cardinality >1, the 'form' editor is selected.");
$this->assertEqual('form', $this->getSelectedEditor($this->entity->id(), $field_name), "Without text processing, cardinality >1, the 'form' editor is selected.");
// Editor selection with text processing, cardinality >1
$this->field_text_instance->settings['text_processing'] = 1;
$this->field_text_instance->save();
$this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "With text processing, cardinality >1, the 'form' editor is selected.");
$this->assertEqual('form', $this->getSelectedEditor($this->entity->id(), $field_name), "With text processing, cardinality >1, the 'form' editor is selected.");
}
/**
......@@ -122,21 +125,24 @@ public function testTextWysiwyg() {
array()
);
// Pretend there is an entity with these items for the field.
$items = array(array('value' => 'Hello, world!', 'format' => 'filtered_html'));
// Create an entity with values for this text field.
$this->entity = entity_create('entity_test', array());
$this->entity->{$field_name}->value = 'Hello, world!';
$this->entity->{$field_name}->format = 'filtered_html';
$this->entity->save();
// Editor selection w/ cardinality 1, text format w/o associated text editor.
$this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "With cardinality 1, and the filtered_html text format, the 'form' editor is selected.");
$this->assertEqual('form', $this->getSelectedEditor($this->entity->id(), $field_name), "With cardinality 1, and the filtered_html text format, the 'form' editor is selected.");
// Editor selection w/ cardinality 1, text format w/ associated text editor.
$items[0]['format'] = 'full_html';
$this->assertEqual('wysiwyg', $this->getSelectedEditor($items, $field_name), "With cardinality 1, and the full_html text format, the 'wysiwyg' editor is selected.");
$this->entity->{$field_name}->format = 'full_html';
$this->entity->save();
$this->assertEqual('wysiwyg', $this->getSelectedEditor($this->entity->id(), $field_name), "With cardinality 1, and the full_html text format, the 'wysiwyg' editor is selected.");
// Editor selection with text processing, cardinality >1
$this->field_textarea_field->cardinality = 2;
$this->field_textarea_field->save();
$items[] = array('value' => 'Hallo, wereld!', 'format' => 'full_html');
$this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected.");
$this->assertEqual('form', $this->getSelectedEditor($this->entity->id(), $field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected.");
}
/**
......@@ -156,16 +162,18 @@ public function testNumber() {
array()
);
// Pretend there is an entity with these items for the field.
$items = array(42, 43);
// Create an entity with values for this text field.
$this->entity = entity_create('entity_test', array());
$this->entity->{$field_name}->value = 42;
$this->entity->save();
// Editor selection with cardinality 1.
$this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "With cardinality 1, the 'form' editor is selected.");
$this->assertEqual('form', $this->getSelectedEditor($this->entity->id(), $field_name), "With cardinality 1, the 'form' editor is selected.");
// Editor selection with cardinality >1.
$this->field_nr_field->cardinality = 2;
$this->field_nr_field->save();
$this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "With cardinality >1, the 'form' editor is selected.");
$this->assertEqual('form', $this->getSelectedEditor($this->entity->id(), $field_name), "With cardinality >1, the 'form' editor is selected.");
}
}
......@@ -96,15 +96,14 @@ public function testSimpleEntityType() {
// Create an entity with values for this text field.
$this->entity = entity_create('entity_test', array());
$this->is_new = TRUE;
$this->entity->{$field_1_name}->value = 'Test';
$this->entity->{$field_2_name}->value = 42;
$this->entity->save();
$entity = entity_load('entity_test', $this->entity->id());
// Verify metadata for field 1.
$instance_1 = field_info_instance($entity->entityType(), $field_1_name, $entity->bundle());
$metadata_1 = $this->metadataGenerator->generateField($entity, $instance_1, Language::LANGCODE_NOT_SPECIFIED, 'default');
$items_1 = $entity->getTranslation(Language::LANGCODE_NOT_SPECIFIED)->get($field_1_name);
$metadata_1 = $this->metadataGenerator->generateFieldMetadata($items_1, 'default');
$expected_1 = array(
'access' => TRUE,
'label' => 'Simple text field',
......@@ -114,8 +113,8 @@ public function testSimpleEntityType() {
$this->assertEqual($expected_1, $metadata_1, 'The correct metadata is generated for the first field.');
// Verify metadata for field 2.
$instance_2 = field_info_instance($entity->entityType(), $field_2_name, $entity->bundle());
$metadata_2 = $this->metadataGenerator->generateField($entity, $instance_2, Language::LANGCODE_NOT_SPECIFIED, 'default');
$items_2 = $entity->getTranslation(Language::LANGCODE_NOT_SPECIFIED)->get($field_2_name);
$metadata_2 = $this->metadataGenerator->generateFieldMetadata($items_2, 'default');
$expected_2 = array(
'access' => TRUE,
'label' => 'Simple number field',
......@@ -169,8 +168,8 @@ public function testEditorWithCustomMetadata() {
$entity = entity_load('entity_test', $this->entity->id());
// Verify metadata.
$instance = field_info_instance($entity->entityType(), $field_name, $entity->bundle());
$metadata = $this->metadataGenerator->generateField($entity, $instance, Language::LANGCODE_NOT_SPECIFIED, 'default');
$items = $entity->getTranslation(Language::LANGCODE_NOT_SPECIFIED)->get($field_name);
$metadata = $this->metadataGenerator->generateFieldMetadata($items, 'default');
$expected = array(
'access' => TRUE,
'label' => 'Rich text field',
......
......@@ -7,8 +7,8 @@
namespace Drupal\edit_test\Plugin\InPlaceEditor;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\edit\EditorBase;
use Drupal\Core\Field\FieldDefinitionInterface;
/**
* Defines the 'wysiwyg' in-place editor.
......@@ -23,7 +23,9 @@ class WysiwygEditor extends EditorBase {
/**
* {@inheritdoc}
*/
function isCompatible(FieldDefinitionInterface $field_definition, array $items) {
public function isCompatible(FieldItemListInterface $items) {
$field_definition = $items->getFieldDefinition();
// This editor is incompatible with multivalued fields.
if ($field_definition->getCardinality() != 1) {
return FALSE;
......@@ -32,8 +34,7 @@ function isCompatible(FieldDefinitionInterface $field_definition, array $items)
// if there is a currently active text format and that text format is the
// 'full_html' text format.
elseif ($field_definition->getSetting('text_processing')) {
$format_id = $items[0]['format'];
if (isset($format_id) && $format_id === 'full_html') {
if ($items[0]->format === 'full_html') {
return TRUE;
}
return FALSE;
......@@ -43,9 +44,8 @@ function isCompatible(FieldDefinitionInterface $field_definition, array $items)
/**
* {@inheritdoc}
*/
function getMetadata(FieldDefinitionInterface $field_definition, array $items) {
$format_id = $items[0]['format'];
$metadata['format'] = $format_id;
function getMetadata(FieldItemListInterface $items) {
$metadata['format'] = $items[0]->format;
return $metadata;
}
......
......@@ -8,8 +8,8 @@
namespace Drupal\editor\Plugin\InPlaceEditor;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\edit\EditPluginInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
/**
* Defines the formatted text in-place editor.
......@@ -24,7 +24,9 @@ class Editor extends PluginBase implements EditPluginInterface {
/**
* {@inheritdoc}
*/
function isCompatible(FieldDefinitionInterface $field_definition, array $items) {
public function isCompatible(FieldItemListInterface $items) {
$field_definition = $items->getFieldDefinition();
// This editor is incompatible with multivalued fields.
if ($field_definition->getCardinality() != 1) {
return FALSE;
......@@ -33,8 +35,7 @@ function isCompatible(FieldDefinitionInterface $field_definition, array $items)
// if there is a currently active text format, that text format has an
// associated editor and that editor supports inline editing.
elseif ($field_definition->getSetting('text_processing')) {
$format_id = $items[0]['format'];
if (isset($format_id) && $editor = editor_load($format_id)) {
if ($editor = editor_load($items[0]->format)) {
$definition = \Drupal::service('plugin.manager.editor')->getDefinition($editor->editor);
if ($definition['supports_inline_editing'] === TRUE) {
return TRUE;
......@@ -48,8 +49,8 @@ function isCompatible(FieldDefinitionInterface $field_definition, array $items)
/**
* {@inheritdoc}
*/
function getMetadata(FieldDefinitionInterface $field_definition, array $items) {
$format_id = $items[0]['format'];
function getMetadata(FieldItemListInterface $items) {
$format_id = $items[0]->format;
$metadata['format'] = $format_id;
$metadata['formatHasTransformations'] = $this->textFormatHasTransformationFilters($format_id);
return $metadata;
......
......@@ -106,13 +106,13 @@ public function setUp() {
}
/**
* Retrieves the FieldInstance object for the given field and returns the
* editor that Edit selects.
* Returns the in-place editor that Edit selects.
*/
protected function getSelectedEditor($items, $field_name, $view_mode = 'default') {
protected function getSelectedEditor($entity_id, $field_name, $view_mode = 'default') {
$entity = entity_load('entity_test', $entity_id, TRUE);
$items = $entity->getTranslation(Language::LANGCODE_NOT_SPECIFIED)->get($field_name);
$options = entity_get_display('entity_test', 'entity_test', $view_mode)->getComponent($field_name);
$field_instance = field_info_instance('entity_test', $field_name, 'entity_test');
return $this->editorSelector->getEditor($options['type'], $field_instance, $items);
return $this->editorSelector->getEditor($options['type'], $items);
}
/**
......@@ -126,21 +126,24 @@ public function testEditorSelection() {
$this->editorManager = new InPlaceEditorManager($this->container->get('container.namespaces'));
$this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
// Pretend there is an entity with these items for the field.
$items = array(array('value' => 'Hello, world!', 'format' => 'filtered_html'));
// Create an entity with values for this text field.
$this->entity = entity_create('entity_test', array());
$this->entity->{$this->field_name}->value = 'Hello, world!';
$this->entity->{$this->field_name}->format = 'filtered_html';
$this->entity->save();
// Editor selection w/ cardinality 1, text format w/o associated text editor.
$this->assertEqual('form', $this->getSelectedEditor($items, $this->field_name), "With cardinality 1, and the filtered_html text format, the 'form' editor is selected.");
$this->assertEqual('form', $this->getSelectedEditor($this->entity->id(), $this->field_name), "With cardinality 1, and the filtered_html text format, the 'form' editor is selected.");
// Editor selection w/ cardinality 1, text format w/ associated text editor.
$items[0]['format'] = 'full_html';
$this->assertEqual('editor', $this->getSelectedEditor($items, $this->field_name), "With cardinality 1, and the full_html text format, the 'editor' editor is selected.");
$this->entity->{$this->field_name}->format = 'full_html';
$this->entity->save();
$this->assertEqual('editor', $this->getSelectedEditor($this->entity->id(), $this->field_name), "With cardinality 1, and the full_html text format, the 'editor' editor is selected.");
// Editor selection with text processing, cardinality >1
$this->field_textarea_field->cardinality = 2;
$this->field_textarea_field->save();
$items[] = array('value' => 'Hallo, wereld!', 'format' => 'full_html');
$this->assertEqual('form', $this->getSelectedEditor($items, $this->field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected.");
$this->assertEqual('form', $this->getSelectedEditor($this->entity->id(), $this->field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected.");
}
/**
......@@ -160,8 +163,8 @@ public function testMetadata() {
$entity = entity_load('entity_test', $this->entity->id());
// Verify metadata.
$instance = field_info_instance($entity->entityType(), $this->field_name, $entity->bundle());
$metadata = $this->metadataGenerator->generateField($entity, $instance, Language::LANGCODE_NOT_SPECIFIED, 'default');
$items = $entity->getTranslation(Language::LANGCODE_NOT_SPECIFIED)->get($this->field_name);
$metadata = $this->metadataGenerator->generateFieldMetadata($items, 'default');
$expected = array(
'access' => TRUE,
'label' => 'Long text field',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment