function paragraphs_library_install in Paragraphs 8
Implements hook_install().
File
- modules/
paragraphs_library/ paragraphs_library.install, line 16 - Install/Update hooks for paragraphs library.
Code
function paragraphs_library_install() {
if (\Drupal::isConfigSyncing()) {
return;
}
if (\Drupal::moduleHandler()
->moduleExists('entity_browser')) {
EntityFormDisplay::load('paragraph.from_library.default')
->setComponent('field_reusable_paragraph', [
'type' => 'entity_browser_entity_reference',
'settings' => [
'entity_browser' => 'paragraphs_library_items',
'open' => TRUE,
'field_widget_display' => 'rendered_entity',
'field_widget_display_settings' => [
'view_mode' => 'summary',
],
'field_widget_remove' => FALSE,
'field_widget_replace' => TRUE,
],
])
->save();
}
// Make sure the "Usage" local task is enabled for library items.
$entity_usage_config = \Drupal::configFactory()
->getEditable('entity_usage.settings');
$tabs_enabled = $entity_usage_config
->get('local_task_enabled_entity_types');
if (is_array($tabs_enabled) && !in_array('paragraphs_library_item', $tabs_enabled)) {
$tabs_enabled[] = 'paragraphs_library_item';
$entity_usage_config
->set('local_task_enabled_entity_types', $tabs_enabled)
->save();
}
// Enable the usage warning message on edit and delete forms.
$edit_warning_enabled = $entity_usage_config
->get('edit_warning_message_entity_types') ?: [];
if (!in_array('paragraphs_library_item', $edit_warning_enabled)) {
$edit_warning_enabled[] = 'paragraphs_library_item';
$entity_usage_config
->set('edit_warning_message_entity_types', $edit_warning_enabled)
->save();
}
$delete_warning_enabled = $entity_usage_config
->get('delete_warning_message_entity_types') ?: [];
if (!in_array('paragraphs_library_item', $delete_warning_enabled)) {
$delete_warning_enabled[] = 'paragraphs_library_item';
$entity_usage_config
->set('delete_warning_message_entity_types', $delete_warning_enabled)
->save();
}
}