menu_link_content.install 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the menu_link_content module.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function menu_link_content_install() {
  10. // Add a higher weight so that menu_link_content_path_update() is called after
  11. // system_path_update() clears the path alias cache.
  12. // @todo remove this when the cache clearing is moved to path module or if
  13. // caching is removed for path aliases due to
  14. // https://www.drupal.org/node/1965074
  15. module_set_weight('menu_link_content', 1);
  16. }
  17. /**
  18. * Add the publishing status entity key to custom menu links.
  19. */
  20. function menu_link_content_update_8601() {
  21. $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  22. $entity_type = $definition_update_manager->getEntityType('menu_link_content');
  23. // Add the published entity key to the menu_link_content entity type.
  24. $entity_keys = $entity_type->getKeys();
  25. $entity_keys['published'] = 'enabled';
  26. $entity_type->set('entity_keys', $entity_keys);
  27. $definition_update_manager->updateEntityType($entity_type);
  28. // @todo The above should be enough, since that is the only definition that
  29. // changed. But \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema varies
  30. // field schema by whether a field is an entity key, so invoke
  31. // EntityDefinitionUpdateManagerInterface::updateFieldStorageDefinition()
  32. // with an unmodified field storage definition to trigger the necessary
  33. // changes. SqlContentEntityStorageSchema::onEntityTypeUpdate() should be
  34. // fixed to automatically handle this.
  35. // @see https://www.drupal.org/node/2554245
  36. $definition_update_manager->updateFieldStorageDefinition($definition_update_manager->getFieldStorageDefinition('enabled', 'menu_link_content'));
  37. return t('The publishing status entity key has been added to custom menu links.');
  38. }