Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds update hook to ensure localgov_numbered_text paragraph is available. #162

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions localgov_paragraphs.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
* Update hooks.
*/

use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Utility\UpdateException;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\paragraphs\Entity\ParagraphsType;
use Symfony\Component\Yaml\Yaml;

/**
* Implements hook_update_N().
Expand Down Expand Up @@ -74,3 +80,33 @@ function localgov_paragraphs_update_9003() {
->load('paragraph.localgov_contact_office_hours')
->save();
}

/**
* Install the localgov_numbered_text paragraph type if it's not installed.
*/
function localgov_paragraphs_update_9004() {

if (ParagraphsType::load('localgov_numbered_text')) {
return 'localgov_numbered_text is already installed';
}

$modulePath = \Drupal::service('extension.list.module')->getPath('localgov_paragraphs');

$paragraphTypeConfig = Yaml::parseFile($modulePath . '/config/install/paragraphs.paragraphs_type.localgov_numbered_text.yml');
ParagraphsType::create($paragraphTypeConfig)->save();

$numberFieldStorageConfig = Yaml::parseFile($modulePath . '/config/install/field.storage.paragraph.localgov_numbered_text_number.yml');
FieldStorageConfig::create($numberFieldStorageConfig)->save();

$textFieldConfig = Yaml::parseFile($modulePath . '/config/install/field.field.paragraph.localgov_numbered_text.localgov_text.yml');
FieldConfig::create($textFieldConfig)->save();

$numberFieldConfig = Yaml::parseFile($modulePath . '/config/install/field.field.paragraph.localgov_numbered_text.localgov_numbered_text_number.yml');
FieldConfig::create($numberFieldConfig)->save();

$entityViewDisplayConfig = Yaml::parseFile($modulePath . '/config/install/core.entity_view_display.paragraph.localgov_numbered_text.default.yml');
EntityViewDisplay::create($entityViewDisplayConfig)->save();

$entityFormDisplayConfig = Yaml::parseFile($modulePath . '/config/install/core.entity_form_display.paragraph.localgov_numbered_text.default.yml');
EntityFormDisplay::create($entityFormDisplayConfig)->save();
}
Loading