paragraphs_sets.install in Paragraphs Sets 8.2
Same filename and directory in other branches
Installation hooks for paragraphs_setss module.
File
paragraphs_sets.installView source
<?php
/**
* @file
* Installation hooks for paragraphs_setss module.
*/
/**
* Implements hook_install().
*/
function paragraphs_sets_install() {
// Assign a weight 1 higher than paragraphs.
module_set_weight('paragraphs_sets', 12);
}
/**
* Implements hook_requirements().
*/
function paragraphs_sets_requirements($phase) {
$requirements = [];
if (!in_array($phase, [
'install',
'runtime',
])) {
return $requirements;
}
// Check version of paragraphs module.
if (\Drupal::moduleHandler()
->moduleExists('paragraphs')) {
$module_info = \Drupal::service('extension.list.module')
->getExtensionInfo('paragraphs');
if (empty($module_info['version'])) {
// Module checked out from git so we assume it is newer than required.
return $requirements;
}
if (version_compare($module_info['version'], '8.x-1.3', '<')) {
$requirements['paragraphs'] = [
'title' => t('Paragraphs version'),
'description' => t('You need to install at least version 8.x-1.3 of the %paragraphs module (installed version is %version).', [
'%paragraphs' => 'Paragraphs',
'%version' => $module_info['version'],
]),
'value' => t('Incompatible version'),
'severity' => REQUIREMENT_ERROR,
];
}
}
return $requirements;
}
/**
* Enable sets for all paragraph fields for backward compatibility.
*/
function paragraphs_sets_update_8201() {
$config_factory = \Drupal::configFactory();
$names = $config_factory
->listAll('core.entity_form_display.');
foreach ($names as $name) {
$config = $config_factory
->getEditable($name);
$content = $config
->get('content');
foreach ($content as $field => $info) {
if ($info['type'] !== 'paragraphs') {
continue;
}
if (!isset($info['third_party_settings']['paragraphs_sets']['paragraphs_sets']['use_paragraphs_sets'])) {
$config_array = $config
->getOriginal();
$config_array['content'][$field]['third_party_settings']['paragraphs_sets']['paragraphs_sets']['use_paragraphs_sets'] = '1';
$config
->setData($config_array);
$config
->save();
}
}
}
}
Functions
Name | Description |
---|---|
paragraphs_sets_install | Implements hook_install(). |
paragraphs_sets_requirements | Implements hook_requirements(). |
paragraphs_sets_update_8201 | Enable sets for all paragraph fields for backward compatibility. |