diff --git a/core/lib/Drupal/Core/Extension/module.api.php b/core/lib/Drupal/Core/Extension/module.api.php index ce72ded..af77c19 100644 --- a/core/lib/Drupal/Core/Extension/module.api.php +++ b/core/lib/Drupal/Core/Extension/module.api.php @@ -693,11 +693,29 @@ function hook_update_N(&$sandbox) { * @see hook_update_N() */ function hook_post_update_NAME(&$sandbox) { + // Example of updating some content. $node = \Drupal\node\Entity\Node::load(123); $node->setTitle('foo'); $node->save(); - return t('Node %nid saved', ['%nid' => $node->id()]); + $result = t('Node %nid saved', ['%nid' => $node->id()]); + + // Example of updating an existing configuration entity. + // This example disables the frontpage view. + $view = \Drupal\views\Entity\View::load('frontpage'); + $view->setStatus(FALSE); + $view->save(); + + // Example of a usecase where some values of views plugins changes. + $view = \Drupal\views\Entity\View::load('frontpage'); + $display = &$view->getDisplay('default'); + // In this example we convert from %1 tokens to twig tokens, see + // https://www.drupal.org/node/2492839 + $display['display_options']['title'] = str_replace('%1', '{{ arguments.1 }}', $display['display_options']['title']); + $view->save(); + + $result .= t('View %view_id saved', [$view->id()]); + return $result; } /**