Issue #2030607 by hussainweb, Mile23, Kingdutch, alexpott, balagan, amateescu, adci_contributor, Xano, mon_franco, cilefen: Expand EntityDisplayBase with methods
parent
b3312d0503
commit
2e92d427d9
|
@ -26,9 +26,9 @@ abstract class ConfigEntityBundleBase extends ConfigEntityBase {
|
|||
// Rename entity displays.
|
||||
if ($this->getOriginalId() !== $this->id()) {
|
||||
foreach ($this->loadDisplays('entity_view_display') as $display) {
|
||||
$new_id = $this->getEntityType()->getBundleOf() . '.' . $this->id() . '.' . $display->mode;
|
||||
$new_id = $this->getEntityType()->getBundleOf() . '.' . $this->id() . '.' . $display->getMode();
|
||||
$display->set('id', $new_id);
|
||||
$display->bundle = $this->id();
|
||||
$display->setTargetBundle($this->id());
|
||||
$display->save();
|
||||
}
|
||||
}
|
||||
|
@ -36,9 +36,9 @@ abstract class ConfigEntityBundleBase extends ConfigEntityBase {
|
|||
// Rename entity form displays.
|
||||
if ($this->getOriginalId() !== $this->id()) {
|
||||
foreach ($this->loadDisplays('entity_form_display') as $form_display) {
|
||||
$new_id = $this->getEntityType()->getBundleOf() . '.' . $this->id() . '.' . $form_display->mode;
|
||||
$new_id = $this->getEntityType()->getBundleOf() . '.' . $this->id() . '.' . $form_display->getMode();
|
||||
$form_display->set('id', $new_id);
|
||||
$form_display->bundle = $this->id();
|
||||
$form_display->setTargetBundle($this->id());
|
||||
$form_display->save();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,11 @@ interface EntityDisplayInterface extends ConfigEntityInterface, EntityWithPlugin
|
|||
* The new object necessarily has the same $targetEntityType and $bundle
|
||||
* properties than the original one.
|
||||
*
|
||||
* @param $view_mode
|
||||
* @param string $view_mode
|
||||
* The view mode for the new object.
|
||||
*
|
||||
* @return static
|
||||
* A duplicate of this object with the given view mode.
|
||||
*/
|
||||
public function createCopy($view_mode);
|
||||
|
||||
|
@ -91,4 +92,46 @@ interface EntityDisplayInterface extends ConfigEntityInterface, EntityWithPlugin
|
|||
*/
|
||||
public function getRenderer($field_name);
|
||||
|
||||
/**
|
||||
* Returns the entity type for which this display is used.
|
||||
*
|
||||
* @return string
|
||||
* The entity type id.
|
||||
*/
|
||||
public function getTargetEntityTypeId();
|
||||
|
||||
/**
|
||||
* Returns the view or form mode to be displayed.
|
||||
*
|
||||
* @return string
|
||||
* The mode to be displayed.
|
||||
*/
|
||||
public function getMode();
|
||||
|
||||
/**
|
||||
* Returns the original view or form mode that was requested.
|
||||
*
|
||||
* @return string
|
||||
* The original mode that was requested.
|
||||
*/
|
||||
public function getOriginalMode();
|
||||
|
||||
/**
|
||||
* Returns the bundle to be displayed.
|
||||
*
|
||||
* @return string
|
||||
* The bundle to be displayed.
|
||||
*/
|
||||
public function getTargetBundle();
|
||||
|
||||
/**
|
||||
* Sets the bundle to be displayed.
|
||||
*
|
||||
* @param string $bundle
|
||||
* The bundle to be displayed.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTargetBundle($bundle);
|
||||
|
||||
}
|
||||
|
|
|
@ -36,21 +36,21 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Entity type to be displayed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $targetEntityType;
|
||||
protected $targetEntityType;
|
||||
|
||||
/**
|
||||
* Bundle to be displayed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $bundle;
|
||||
protected $bundle;
|
||||
|
||||
/**
|
||||
* A list of field definitions eligible for configuration in this display.
|
||||
|
@ -64,7 +64,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
public $mode = self::CUSTOM_MODE;
|
||||
protected $mode = self::CUSTOM_MODE;
|
||||
|
||||
/**
|
||||
* Whether this display is enabled or not. If the entity (form) display
|
||||
|
@ -94,7 +94,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
public $originalMode;
|
||||
protected $originalMode;
|
||||
|
||||
/**
|
||||
* The plugin objects used for this display, keyed by field name.
|
||||
|
@ -144,6 +144,91 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
|
|||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the display.
|
||||
*
|
||||
* This fills in default options for components:
|
||||
* - that are not explicitly known as either "visible" or "hidden" in the
|
||||
* display,
|
||||
* - or that are not supposed to be configurable.
|
||||
*/
|
||||
protected function init() {
|
||||
// Only populate defaults for "official" view modes and form modes.
|
||||
if ($this->mode !== static::CUSTOM_MODE) {
|
||||
// Fill in defaults for extra fields.
|
||||
$context = $this->displayContext == 'view' ? 'display' : $this->displayContext;
|
||||
$extra_fields = \Drupal::entityManager()->getExtraFields($this->targetEntityType, $this->bundle);
|
||||
$extra_fields = isset($extra_fields[$context]) ? $extra_fields[$context] : array();
|
||||
foreach ($extra_fields as $name => $definition) {
|
||||
if (!isset($this->content[$name]) && !isset($this->hidden[$name])) {
|
||||
// Extra fields are visible by default unless they explicitly say so.
|
||||
if (!isset($definition['visible']) || $definition['visible'] == TRUE) {
|
||||
$this->content[$name] = array(
|
||||
'weight' => $definition['weight']
|
||||
);
|
||||
}
|
||||
else {
|
||||
$this->hidden[$name] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fill in defaults for fields.
|
||||
$fields = $this->getFieldDefinitions();
|
||||
foreach ($fields as $name => $definition) {
|
||||
if (!$definition->isDisplayConfigurable($this->displayContext) || (!isset($this->content[$name]) && !isset($this->hidden[$name]))) {
|
||||
$options = $definition->getDisplayOptions($this->displayContext);
|
||||
|
||||
if (!empty($options['type']) && $options['type'] == 'hidden') {
|
||||
$this->hidden[$name] = TRUE;
|
||||
}
|
||||
elseif ($options) {
|
||||
$this->content[$name] = $this->pluginManager->prepareConfiguration($definition->getType(), $options);
|
||||
}
|
||||
// Note: (base) fields that do not specify display options are not
|
||||
// tracked in the display at all, in order to avoid cluttering the
|
||||
// configuration that gets saved back.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTargetEntityTypeId() {
|
||||
return $this->targetEntityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMode() {
|
||||
return $this->get('mode');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOriginalMode() {
|
||||
return $this->get('originalMode');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTargetBundle() {
|
||||
return $this->bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setTargetBundle($bundle) {
|
||||
$this->set('bundle', $bundle);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -213,55 +298,6 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
|
|||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the display.
|
||||
*
|
||||
* This fills in default options for components:
|
||||
* - that are not explicitly known as either "visible" or "hidden" in the
|
||||
* display,
|
||||
* - or that are not supposed to be configurable.
|
||||
*/
|
||||
protected function init() {
|
||||
// Only populate defaults for "official" view modes and form modes.
|
||||
if ($this->mode !== static::CUSTOM_MODE) {
|
||||
// Fill in defaults for extra fields.
|
||||
$context = $this->displayContext == 'view' ? 'display' : $this->displayContext;
|
||||
$extra_fields = \Drupal::entityManager()->getExtraFields($this->targetEntityType, $this->bundle);
|
||||
$extra_fields = isset($extra_fields[$context]) ? $extra_fields[$context] : array();
|
||||
foreach ($extra_fields as $name => $definition) {
|
||||
if (!isset($this->content[$name]) && !isset($this->hidden[$name])) {
|
||||
// Extra fields are visible by default unless they explicitly say so.
|
||||
if (!isset($definition['visible']) || $definition['visible'] == TRUE) {
|
||||
$this->content[$name] = array(
|
||||
'weight' => $definition['weight']
|
||||
);
|
||||
}
|
||||
else {
|
||||
$this->hidden[$name] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fill in defaults for fields.
|
||||
$fields = $this->getFieldDefinitions();
|
||||
foreach ($fields as $name => $definition) {
|
||||
if (!$definition->isDisplayConfigurable($this->displayContext) || (!isset($this->content[$name]) && !isset($this->hidden[$name]))) {
|
||||
$options = $definition->getDisplayOptions($this->displayContext);
|
||||
|
||||
if (!empty($options['type']) && $options['type'] == 'hidden') {
|
||||
$this->hidden[$name] = TRUE;
|
||||
}
|
||||
elseif ($options) {
|
||||
$this->content[$name] = $this->pluginManager->prepareConfiguration($definition->getType(), $options);
|
||||
}
|
||||
// Note: (base) fields that do not specify display options are not
|
||||
// tracked in the display at all, in order to avoid cluttering the
|
||||
// configuration that gets saved back.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -149,7 +149,7 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
*/
|
||||
protected function getFieldDefinitions() {
|
||||
$context = $this->displayContext;
|
||||
return array_filter($this->entityManager->getFieldDefinitions($this->entity->targetEntityType, $this->entity->bundle), function(FieldDefinitionInterface $field_definition) use ($context) {
|
||||
return array_filter($this->entityManager->getFieldDefinitions($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle()), function(FieldDefinitionInterface $field_definition) use ($context) {
|
||||
return $field_definition->isDisplayConfigurable($context);
|
||||
});
|
||||
}
|
||||
|
@ -164,13 +164,13 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
$extra_fields = $this->getExtraFields();
|
||||
|
||||
$form += array(
|
||||
'#entity_type' => $this->entity->targetEntityType,
|
||||
'#bundle' => $this->entity->bundle,
|
||||
'#entity_type' => $this->entity->getTargetEntityTypeId(),
|
||||
'#bundle' => $this->entity->getTargetBundle(),
|
||||
'#fields' => array_keys($field_definitions),
|
||||
'#extra' => array_keys($extra_fields),
|
||||
);
|
||||
|
||||
if (empty($field_definitions) && empty($extra_fields) && $route_info = FieldUI::getOverviewRouteInfo($this->entity->targetEntityType, $this->entity->bundle)) {
|
||||
if (empty($field_definitions) && empty($extra_fields) && $route_info = FieldUI::getOverviewRouteInfo($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle())) {
|
||||
drupal_set_message($this->t('There are no fields yet added. You can add new fields on the <a href="@link">Manage fields</a> page.', array('@link' => $route_info->toString())), 'warning');
|
||||
return $form;
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
$form['fields'] = $table;
|
||||
|
||||
// Custom display settings.
|
||||
if ($this->entity->mode == 'default') {
|
||||
if ($this->entity->getMode() == 'default') {
|
||||
// Only show the settings if there is at least one custom display mode.
|
||||
if ($display_modes = $this->getDisplayModes()) {
|
||||
$form['modes'] = array(
|
||||
|
@ -538,7 +538,7 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
$form_values = $form_state->getValues();
|
||||
|
||||
// Handle the 'display modes' checkboxes if present.
|
||||
if ($this->entity->mode == 'default' && !empty($form_values['display_modes_custom'])) {
|
||||
if ($this->entity->getMode() == 'default' && !empty($form_values['display_modes_custom'])) {
|
||||
$display_modes = $this->getDisplayModes();
|
||||
$current_statuses = $this->getDisplayStatuses();
|
||||
|
||||
|
@ -548,8 +548,8 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
// If no display exists for the newly enabled view mode, initialize
|
||||
// it with those from the 'default' view mode, which were used so
|
||||
// far.
|
||||
if (!$this->entityManager->getStorage($this->entity->getEntityTypeId())->load($this->entity->targetEntityType . '.' . $this->entity->bundle . '.' . $mode)) {
|
||||
$display = $this->getEntityDisplay($this->entity->targetEntityType, $this->entity->bundle, 'default')->createCopy($mode);
|
||||
if (!$this->entityManager->getStorage($this->entity->getEntityTypeId())->load($this->entity->getTargetEntityTypeId() . '.' . $this->entity->getTargetBundle() . '.' . $mode)) {
|
||||
$display = $this->getEntityDisplay($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle(), 'default')->createCopy($mode);
|
||||
$display->save();
|
||||
}
|
||||
|
||||
|
@ -854,7 +854,7 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
*/
|
||||
protected function getExtraFields() {
|
||||
$context = $this->displayContext == 'view' ? 'display' : $this->displayContext;
|
||||
$extra_fields = $this->entityManager->getExtraFields($this->entity->targetEntityType, $this->entity->bundle);
|
||||
$extra_fields = $this->entityManager->getExtraFields($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle());
|
||||
return isset($extra_fields[$context]) ? $extra_fields[$context] : array();
|
||||
}
|
||||
|
||||
|
@ -967,7 +967,7 @@ abstract class EntityDisplayFormBase extends EntityForm {
|
|||
$display_entity_type = $this->entity->getEntityTypeId();
|
||||
$entity_type = $this->entityManager->getDefinition($display_entity_type);
|
||||
$config_prefix = $entity_type->getConfigPrefix();
|
||||
$ids = $this->configFactory()->listAll($config_prefix . '.' . $this->entity->targetEntityType . '.' . $this->entity->bundle . '.');
|
||||
$ids = $this->configFactory()->listAll($config_prefix . '.' . $this->entity->getTargetEntityTypeId() . '.' . $this->entity->getTargetBundle() . '.');
|
||||
foreach ($ids as $id) {
|
||||
$config_id = str_replace($config_prefix . '.', '', $id);
|
||||
list(,, $display_mode) = explode('.', $config_id);
|
||||
|
|
|
@ -67,7 +67,7 @@ class EntityFormDisplayEditForm extends EntityDisplayFormBase {
|
|||
if ($configuration && $configuration['type'] != 'hidden') {
|
||||
$plugin = $this->pluginManager->getInstance(array(
|
||||
'field_definition' => $field_definition,
|
||||
'form_mode' => $this->entity->mode,
|
||||
'form_mode' => $this->entity->getMode(),
|
||||
'configuration' => $configuration
|
||||
));
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ class EntityFormDisplayEditForm extends EntityDisplayFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getDisplayModes() {
|
||||
return $this->entityManager->getFormModes($this->entity->targetEntityType);
|
||||
return $this->entityManager->getFormModes($this->entity->getTargetEntityTypeId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,10 +105,10 @@ class EntityFormDisplayEditForm extends EntityDisplayFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getOverviewUrl($mode) {
|
||||
$entity_type = $this->entityManager->getDefinition($this->entity->targetEntityType);
|
||||
$entity_type = $this->entityManager->getDefinition($this->entity->getTargetEntityTypeId());
|
||||
$field_entity_type = $entity_type->getBundleEntityType() != 'bundle'? $entity_type->getBundleEntityType() : $entity_type->id();
|
||||
return Url::fromRoute('entity.entity_form_display.' . $field_entity_type . '.form_mode', [
|
||||
$this->bundleEntityTypeId => $this->entity->bundle,
|
||||
$this->bundleEntityTypeId => $this->entity->getTargetBundle(),
|
||||
'form_mode_name' => $mode,
|
||||
]);
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ class EntityFormDisplayEditForm extends EntityDisplayFormBase {
|
|||
$settings_form[$module] = $this->moduleHandler->invoke($module, 'field_widget_third_party_settings_form', array(
|
||||
$plugin,
|
||||
$field_definition,
|
||||
$this->entity->mode,
|
||||
$this->entity->getMode(),
|
||||
$form,
|
||||
$form_state,
|
||||
));
|
||||
|
@ -139,7 +139,7 @@ class EntityFormDisplayEditForm extends EntityDisplayFormBase {
|
|||
$context = array(
|
||||
'widget' => $plugin,
|
||||
'field_definition' => $field_definition,
|
||||
'form_mode' => $this->entity->mode,
|
||||
'form_mode' => $this->entity->getMode(),
|
||||
);
|
||||
$this->moduleHandler->alter('field_widget_settings_summary', $summary, $context);
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
|||
if ($configuration && $configuration['type'] != 'hidden') {
|
||||
$plugin = $this->pluginManager->getInstance(array(
|
||||
'field_definition' => $field_definition,
|
||||
'view_mode' => $this->entity->mode,
|
||||
'view_mode' => $this->entity->getMode(),
|
||||
'configuration' => $configuration
|
||||
));
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getDisplayModes() {
|
||||
return $this->entityManager->getViewModes($this->entity->targetEntityType);
|
||||
return $this->entityManager->getViewModes($this->entity->getTargetEntityTypeId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -139,10 +139,10 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getOverviewUrl($mode) {
|
||||
$entity_type = $this->entityManager->getDefinition($this->entity->targetEntityType);
|
||||
$entity_type = $this->entityManager->getDefinition($this->entity->getTargetEntityTypeId());
|
||||
$field_entity_type = $entity_type->getBundleEntityType() != 'bundle'? $entity_type->getBundleEntityType() : $entity_type->id();
|
||||
return Url::fromRoute('entity.entity_view_display.' . $field_entity_type . '.view_mode', [
|
||||
$this->bundleEntityTypeId => $this->entity->bundle,
|
||||
$this->bundleEntityTypeId => $this->entity->getTargetBundle(),
|
||||
'view_mode_name' => $mode,
|
||||
]);
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
|||
$settings_form[$module] = $this->moduleHandler->invoke($module, 'field_formatter_third_party_settings_form', array(
|
||||
$plugin,
|
||||
$field_definition,
|
||||
$this->entity->mode,
|
||||
$this->entity->getMode(),
|
||||
$form,
|
||||
$form_state,
|
||||
));
|
||||
|
@ -188,7 +188,7 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase {
|
|||
$context = array(
|
||||
'formatter' => $plugin,
|
||||
'field_definition' => $field_definition,
|
||||
'view_mode' => $this->entity->mode,
|
||||
'view_mode' => $this->entity->getMode(),
|
||||
);
|
||||
$this->moduleHandler->alter('field_formatter_settings_summary', $summary, $context);
|
||||
}
|
||||
|
|
|
@ -87,15 +87,15 @@ class EntityDisplayTest extends KernelTestBase {
|
|||
|
||||
// Check that CreateCopy() creates a new component that can be correclty
|
||||
// saved.
|
||||
EntityViewMode::create(array('id' => $display->targetEntityType . '.other_view_mode', 'targetEntityType' => $display->targetEntityType))->save();
|
||||
EntityViewMode::create(array('id' => $display->getTargetEntityTypeId() . '.other_view_mode', 'targetEntityType' => $display->getTargetEntityTypeId()))->save();
|
||||
$new_display = $display->createCopy('other_view_mode');
|
||||
$new_display->save();
|
||||
$new_display = entity_load('entity_view_display', $new_display->id());
|
||||
$dependencies = $new_display->calculateDependencies();
|
||||
$this->assertEqual(array('config' => array('core.entity_view_mode.entity_test.other_view_mode'), 'module' => array('entity_test')), $dependencies);
|
||||
$this->assertEqual($new_display->targetEntityType, $display->targetEntityType);
|
||||
$this->assertEqual($new_display->bundle, $display->bundle);
|
||||
$this->assertEqual($new_display->mode, 'other_view_mode');
|
||||
$this->assertEqual($new_display->getTargetEntityTypeId(), $display->getTargetEntityTypeId());
|
||||
$this->assertEqual($new_display->getTargetBundle(), $display->getTargetBundle());
|
||||
$this->assertEqual($new_display->getMode(), 'other_view_mode');
|
||||
$this->assertEqual($new_display->getComponents(), $display->getComponents());
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ class EntityDisplayTest extends KernelTestBase {
|
|||
// Check that entity_get_display() returns the correct object.
|
||||
$display = entity_get_display('entity_test', 'entity_test', 'default');
|
||||
$this->assertFalse($display->isNew());
|
||||
$this->assertEqual($display->id, 'entity_test.entity_test.default');
|
||||
$this->assertEqual($display->id(), 'entity_test.entity_test.default');
|
||||
$this->assertEqual($display->getComponent('component_1'), array( 'weight' => 10, 'settings' => array(), 'third_party_settings' => array()));
|
||||
}
|
||||
|
||||
|
@ -287,11 +287,11 @@ class EntityDisplayTest extends KernelTestBase {
|
|||
$old_form_display = entity_load('entity_form_display', 'node.article.default');
|
||||
$this->assertFalse((bool) $old_form_display);
|
||||
$new_display = entity_load('entity_view_display', 'node.article_rename.default');
|
||||
$this->assertEqual('article_rename', $new_display->bundle);
|
||||
$this->assertEqual('node.article_rename.default', $new_display->id);
|
||||
$this->assertEqual('article_rename', $new_display->getTargetBundle());
|
||||
$this->assertEqual('node.article_rename.default', $new_display->id());
|
||||
$new_form_display = entity_load('entity_form_display', 'node.article_rename.default');
|
||||
$this->assertEqual('article_rename', $new_form_display->bundle);
|
||||
$this->assertEqual('node.article_rename.default', $new_form_display->id);
|
||||
$this->assertEqual('article_rename', $new_form_display->getTargetBundle());
|
||||
$this->assertEqual('node.article_rename.default', $new_form_display->id());
|
||||
|
||||
$expected_view_dependencies = array(
|
||||
'config' => array('field.field.node.article_rename.body', 'node.type.article_rename'),
|
||||
|
|
|
@ -39,7 +39,7 @@ class EntityFormDisplayTest extends KernelTestBase {
|
|||
// Check that entity_get_form_display() returns the correct object.
|
||||
$form_display = entity_get_form_display('entity_test', 'entity_test', 'default');
|
||||
$this->assertFalse($form_display->isNew());
|
||||
$this->assertEqual($form_display->id, 'entity_test.entity_test.default');
|
||||
$this->assertEqual($form_display->id(), 'entity_test.entity_test.default');
|
||||
$this->assertEqual($form_display->getComponent('component_1'), array('weight' => 10, 'settings' => array(), 'third_party_settings' => array()));
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ function history_cron() {
|
|||
*/
|
||||
function history_node_view_alter(array &$build, EntityInterface $node, EntityViewDisplayInterface $display) {
|
||||
// Update the history table, stating that this user viewed this node.
|
||||
if (($display->originalMode === 'full') && \Drupal::currentUser()->isAuthenticated()) {
|
||||
if (($display->getOriginalMode() === 'full') && \Drupal::currentUser()->isAuthenticated()) {
|
||||
// When the window's "load" event is triggered, mark the node as read.
|
||||
// This still allows for Drupal behaviors (which are triggered on the
|
||||
// "DOMContentReady" event) to add "new" and "updated" indicators.
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\Core\Config\Entity\EntityDisplayBaseTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\Core\Config\Entity;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\entity\EntityDisplayBase
|
||||
*
|
||||
* @group Config
|
||||
*/
|
||||
class EntityDisplayBaseTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::getTargetEntityTypeId()
|
||||
*/
|
||||
public function testGetTargetEntityTypeId() {
|
||||
$mock = $this->getMockForAbstractClass('\Drupal\Core\Entity\EntityDisplayBase', [], '', FALSE);
|
||||
$reflection = new \ReflectionProperty($mock, 'targetEntityType');
|
||||
$reflection->setAccessible(TRUE);
|
||||
$reflection->setValue($mock, 'test');
|
||||
$this->assertEquals('test', $mock->getTargetEntityTypeId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getMode()
|
||||
*/
|
||||
public function testGetMode() {
|
||||
$mock = $this->getMockForAbstractClass('\Drupal\Core\Entity\EntityDisplayBase', [], '', FALSE);
|
||||
$reflection = new \ReflectionProperty($mock, 'mode');
|
||||
$reflection->setAccessible(TRUE);
|
||||
$reflection->setValue($mock, 'test');
|
||||
$this->assertEquals('test', $mock->getMode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getOriginalMode()
|
||||
*/
|
||||
public function testGetOriginalMode() {
|
||||
$mock = $this->getMockForAbstractClass('\Drupal\Core\Entity\EntityDisplayBase', [], '', FALSE);
|
||||
$reflection = new \ReflectionProperty($mock, 'originalMode');
|
||||
$reflection->setAccessible(TRUE);
|
||||
$reflection->setValue($mock, 'test');
|
||||
$this->assertEquals('test', $mock->getOriginalMode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getDisplayBundle()
|
||||
*/
|
||||
public function testGetDisplayBundle() {
|
||||
$mock = $this->getMockForAbstractClass('\Drupal\Core\Entity\EntityDisplayBase', [], '', FALSE);
|
||||
$reflection = new \ReflectionProperty($mock, 'bundle');
|
||||
$reflection->setAccessible(TRUE);
|
||||
$reflection->setValue($mock, 'test');
|
||||
$this->assertEquals('test', $mock->getTargetBundle());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::setDisplayBundle()
|
||||
*/
|
||||
public function testSetDisplayBundle() {
|
||||
$mock = $this->getMockForAbstractClass('\Drupal\Core\Entity\EntityDisplayBase', [], '', FALSE);
|
||||
$reflection = new \ReflectionProperty($mock, 'bundle');
|
||||
$reflection->setAccessible(TRUE);
|
||||
$mock->setTargetBundle('test');
|
||||
$this->assertEquals('test', $reflection->getValue($mock));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue