Commit 2735f129 authored by alexpott's avatar alexpott
Browse files

Issue #2333501 by swentel | marcvangend: Implement ThirdPartySettingsInterface...

Issue #2333501 by swentel | marcvangend: Implement ThirdPartySettingsInterface in EntityView|FormDisplay.
parent 47480954
......@@ -77,6 +77,11 @@ core.entity_view_display.*.*.*:
sequence:
- type: boolean
label: 'Value'
third_party_settings:
type: sequence
label: 'Third party settings'
sequence:
- type: entity_view_display.third_party.[%key]
# Overview configuration information for form mode displays.
core.entity_form_display.*.*.*:
......@@ -109,9 +114,11 @@ core.entity_form_display.*.*.*:
sequence:
- type: boolean
label: 'Component'
dependencies:
type: config_dependencies
label: 'Dependencies'
third_party_settings:
type: sequence
label: 'Third party settings'
sequence:
- type: entity_form_display.third_party.[%key]
# Default schema for entity display field with undefined type.
entity_view_display.field.*:
......
......@@ -7,10 +7,12 @@
namespace Drupal\Core\Entity\Display;
use Drupal\Core\Config\Entity\ThirdPartySettingsInterface;
/**
* Provides a common interface for entity displays.
*/
interface EntityDisplayInterface {
interface EntityDisplayInterface extends ThirdPartySettingsInterface {
/**
* Creates a duplicate of the entity display object on a different view mode.
......
......@@ -11,12 +11,15 @@
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Entity\Display\EntityDisplayInterface;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\Core\Config\Entity\ThirdPartySettingsTrait;
/**
* Provides a common base class for entity view and form displays.
*/
abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDisplayInterface {
use ThirdPartySettingsTrait;
/**
* Unique ID for the config entity.
*
......
......@@ -8,14 +8,14 @@
namespace Drupal\entity\Tests;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\simpletest\DrupalUnitTestBase;
use Drupal\simpletest\KernelTestBase;
/**
* Tests the entity display configuration entities.
*
* @group entity
*/
class EntityDisplayTest extends DrupalUnitTestBase {
class EntityDisplayTest extends KernelTestBase {
public static $modules = array('entity', 'field', 'entity_test', 'user', 'text', 'field_test', 'node', 'system');
......@@ -58,6 +58,11 @@ public function testEntityDisplayCRUD() {
$this->assertEqual($display->getComponent($name), $expected[$name]);
}
// Ensure that third party settings were added to the config entity.
// These are added by entity_test_entity_presave() implemented in
// entity_test module.
$this->assertEqual('bar', $display->getThirdPartySetting('entity_test', 'foo'), 'Third party settings were added to the entity view display.');
// Check that getComponents() returns options for all components.
$expected['name'] = array(
'label' => 'hidden',
......@@ -288,7 +293,7 @@ public function testRenameDeleteBundle() {
$expected_view_dependencies = array(
'entity' => array('field.instance.node.article_rename.body', 'node.type.article_rename'),
'module' => array('text', 'user')
'module' => array('entity_test', 'text', 'user')
);
// Check that the display has dependencies on the bundle, fields and the
// modules that provide the formatters.
......
entity_view_display.third_party.entity_test:
type: mapping
label: 'Schema for entity_test module additions to entity_view_display entity'
mapping:
foo:
type: string
label: 'Label for foo'
......@@ -369,6 +369,10 @@ function entity_test_entity_presave(EntityInterface $entity) {
if (isset($GLOBALS['entity_test_throw_exception'])) {
throw new Exception('Entity presave exception', 1);
}
if ($entity->getEntityType()->id() == 'entity_view_display') {
$entity->setThirdPartySetting('entity_test', 'foo', 'bar');
}
}
/**
......
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