summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormicropat2016-09-16 01:02:36 -0700
committermicropat2016-09-16 01:02:36 -0700
commit69e3d703db0b18b40a7c0dfdc92caf92532aef2e (patch)
tree111d5a8bf24115e981b43a7e3f46bff62c9621ac
parente9786272fa42d8bf603ce052e2a86a7b09317c7f (diff)
Fix new default weights per node types
Fix overwriting of $display_weight
-rw-r--r--addtoany.install15
1 files changed, 5 insertions, 10 deletions
diff --git a/addtoany.install b/addtoany.install
index bb9afac..7d1c94c 100644
--- a/addtoany.install
+++ b/addtoany.install
@@ -21,7 +21,7 @@ function addtoany_install() {
$storage = \Drupal::entityTypeManager()->getStorage('entity_view_display');
foreach ($node_enable_by_default as $bundle => $viewmodes) {
// Set a default weight per node type.
- $display_weight = ($bundle == 'page') ? 101 : 5;
+ $display_weight = ($bundle == 'article') ? 5 : 101;
foreach ($viewmodes as $viewmode) {
// Get the config entity for this bundle and view mode.
@@ -44,6 +44,7 @@ function addtoany_update_8101(&$sandbox) {
$display_in_teasers = $addtoany_settings->getOriginal('display_in_teasers');
$display_in_nodecont = $addtoany_settings->getOriginal('display_in_nodecont');
$display_weight = $addtoany_settings->getOriginal('display_weight');
+ $new_display_weight = $display_weight;
// The entity display repository stores which view modes are enabled.
$entity_display_repository = \Drupal::getContainer()->get('entity_display.repository');
@@ -64,20 +65,14 @@ function addtoany_update_8101(&$sandbox) {
// Check if the old default weight was set.
if ($display_weight == 10) {
- if ($bundle == 'article') {
- // Set the new default weight for articles.
- $display_weight = 5;
- }
- else {
- // Set the new default weight for pages and other node types.
- $display_weight = 101;
- }
+ // Set the new default weight per node type.
+ $new_display_weight = ($bundle == 'article') ? 5 : 101;
}
// Loop over the view modes and apply new settings to match the old.
foreach ($view_modes as $view_mode => $view_mode_info) {
$display = EntityViewDisplay::load('node.' . $bundle . '.' . $view_mode);
- $display->setComponent('addtoany', ['weight' => $display_weight])->save();
+ $display->setComponent('addtoany', ['weight' => $new_display_weight])->save();
}
}
}