zaya-1.0.x-dev/zaya.install
zaya.install
<?php
/**
* @file
* Install/uninstall/update hooks.
*/
use Drupal\user\Entity\Role;
/**
* @file
* Install, update and uninstall functions for the zaya module.
*/
/**
* Implements hook_install().
*/
function zaya_install(): void {
// If media types exists add all to
// field.field.node.zaya_resource.field_media.yml we cannot
// trust in media types installed because depends on standard profile.
// @todo change with recipes in core, as we can depend on recipes to
// install media types
$new_target_bundles = [];
$media_bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('media');
foreach ($media_bundles as $bundle_key => $bundle_info) {
$new_target_bundles[$bundle_key] = $bundle_key;
}
$zaya_resource_zaya_media_config = \Drupal::configFactory()->getEditable('field.field.node.zaya_resource.zaya_media');
if (!$zaya_resource_zaya_media_config->isNew()) {
// This is an installed config so must exist, no need to check.
$field_settings = $zaya_resource_zaya_media_config->get('settings');
$configured_target_bundles = $field_settings['handler_settings']['target_bundles'] ?: [];
$field_settings['handler_settings']['target_bundles'] = array_merge($configured_target_bundles, $new_target_bundles);
$zaya_resource_zaya_media_config->set('settings', $field_settings);
}
// Let content_editor role to access the group.
$content_editor_role = Role::load('content_editor');
if ($content_editor_role) {
$content_editor_role->grantPermission('access group overview');
$content_editor_role->save();
}
}
