summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormicropat2016-09-15 23:31:22 -0700
committermicropat2016-09-15 23:31:22 -0700
commite9786272fa42d8bf603ce052e2a86a7b09317c7f (patch)
treea467e60314e30069a25369cc09fa4efd73464288
parente223eb6ea40985aeb7073f9b961ef8749fb0b9cf (diff)
Set new default weights per node type
Give Articles a default weight of 5, so the extra field is after Body (0) and before Tags (10). Give Pages a default weight of 101, so the extra field is after Body (100), and the same as Links (101) but seems to display after Links instead of before, unfortunately. Other node types default to the same weight as Pages.
-rw-r--r--addtoany.install17
1 files changed, 16 insertions, 1 deletions
diff --git a/addtoany.install b/addtoany.install
index c535289..bb9afac 100644
--- a/addtoany.install
+++ b/addtoany.install
@@ -20,11 +20,14 @@ function addtoany_install() {
// Get the config entity storage handler.
$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;
+
foreach ($viewmodes as $viewmode) {
// Get the config entity for this bundle and view mode.
$display = $storage->load('node.' . $bundle . '.' . $viewmode);
// Enable the AddToAny extra field and save the config.
- $display->setComponent('addtoany')->save();
+ $display->setComponent('addtoany', ['weight' => $display_weight])->save();
}
}
}
@@ -59,6 +62,18 @@ function addtoany_update_8101(&$sandbox) {
unset($view_modes['teaser']);
}
+ // 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;
+ }
+ }
+
// 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);