Commit 7239111b authored by oknate's avatar oknate Committed by Wim Leers

Issue #2841964 by oknate, Wim Leers, daften, phenaproxima, mstef, marcoscano:...

Issue #2841964 by oknate, Wim Leers, daften, phenaproxima, mstef, marcoscano: [config dependencies] When using view modes as display plugins, those config dependencies aren't in the export
parent baceb17d
......@@ -59,4 +59,28 @@ class ViewModeFieldFormatter extends EntityReferenceFieldFormatter {
return 'entity_reference_entity_view';
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
$definition = $this->getPluginDefinition();
$view_mode = $definition['view_mode'];
$view_modes = [];
foreach ($definition['entity_types'] as $type) {
$view_modes[] = "$type.$view_mode";
}
$entity_view_modes = $this->entityTypeManager
->getStorage('entity_view_mode')
->loadMultiple($view_modes);
foreach ($entity_view_modes as $view_mode) {
$this->addDependency($view_mode->getConfigDependencyKey(), $view_mode->getConfigDependencyName());
}
return $this->dependencies;
}
}
......@@ -53,4 +53,28 @@ class ViewModeFieldFormatterTest extends EntityEmbedTestBase {
}
}
/**
* Tests dependencies on EntityViewMode config entities.
*/
public function testViewModeDependencies() {
$button = $this->container
->get('entity_type.manager')
->getStorage('embed_button')
->load('node');
$config = $button->get('type_settings');
$config['display_plugins'] = ['view_mode:node.teaser'];
$button->set('type_settings', $config);
$button->save();
$dependencies = $button->getDependencies();
$this->assertContains('core.entity_view_mode.node.teaser', $dependencies['config']);
// Test that removing teaser view mode removes the dependency.
$config['display_plugins'] = ['view_mode:node.full'];
$button->set('type_settings', $config);
$button->save();
$dependencies = $button->getDependencies();
$this->assertNotContains('core.entity_view_mode.node.teaser', $dependencies['config']);
}
}
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