bootstrap_paragraphs.install in Bootstrap Paragraphs 8
Same filename and directory in other branches
Install, uninstall and update hooks for Boostrap Paragraphs module.
File
bootstrap_paragraphs.installView source
<?php
/**
* @file
* Install, uninstall and update hooks for Boostrap Paragraphs module.
*/
use Symfony\Component\Yaml\Yaml;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
/**
* Makes image linkable.
*/
function bootstrap_paragraphs_update_8001() {
// The link module was added as a dependency. Making sure it is enabled prior
// to the update.
if (!\Drupal::moduleHandler()
->moduleExists('link')) {
throw new \Drupal\Core\Utility\UpdateException("The Link module is now a dependency of the Bootstrap Paragraphs module. Please install the module and try update again.");
}
else {
$bs_path = drupal_get_path('module', 'bootstrap_paragraphs');
// Create field.
$field_storage_yml = Yaml::parse(file_get_contents($bs_path . '/config/install/field.storage.paragraph.field_link.yml'));
if (!FieldStorageConfig::loadByName($field_storage_yml['entity_type'], $field_storage_yml['field_name'])) {
FieldStorageConfig::create($field_storage_yml)
->save();
}
$field_storage_yml = Yaml::parse(file_get_contents($bs_path . '/config/install/field.field.paragraph.image.field_link.yml'));
if (!FieldConfig::loadByName($field_storage_yml['entity_type'], $field_storage_yml['bundle'], $field_storage_yml['field_name'])) {
FieldConfig::create($field_storage_yml)
->save();
}
$config = \Drupal::configFactory()
->getEditable('core.entity_form_display.paragraph.image.default');
// Add dependencies.
$dependencies = $config
->get('dependencies');
$dependencies['config'][] = 'field.field.paragraph.image.field_link';
$dependencies['module'][] = 'link';
$config
->set('dependencies', $dependencies);
// Add Field Link.
$config
->set('content.field_link', [
'weight' => 3,
'settings' => [
'placeholder_url' => '',
'placeholder_title' => '',
],
'third_party_settings' => [],
'type' => 'link_default',
]);
$config
->save(TRUE);
$config = \Drupal::configFactory()
->getEditable('core.entity_view_display.paragraph.image.default');
// Add dependencies.
$dependencies = $config
->get('dependencies');
$dependencies['config'][] = 'field.field.paragraph.image.field_link';
$dependencies['module'][] = 'link';
$config
->set('dependencies', $dependencies);
// Add Field Link.
$config
->set('content.field_link', [
'weight' => 3,
'label' => 'hidden',
'settings' => [
'trim_length' => NULL,
'url_only' => FALSE,
'url_plain' => FALSE,
'rel' => '0',
'target' => '0',
],
'third_party_settings' => [],
'type' => 'link_default',
]);
$config
->save(TRUE);
}
}
Functions
Name![]() |
Description |
---|---|
bootstrap_paragraphs_update_8001 | Makes image linkable. |