opigno_certificate.install in Opigno certificate 8
Same filename and directory in other branches
Install, update and uninstall functions for the Opigno Certificate module.
File
opigno_certificate.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the Opigno Certificate module.
*/
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\opigno_certificate\Entity\OpignoCertificate;
use Drupal\user\Entity\Role;
/**
* Creates default certificate.
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
function opigno_certificate_install() {
// Create default certificate.
$certificate = OpignoCertificate::create([
'bundle' => 'template',
'label' => t('Default certificate'),
]);
$certificate
->save();
}
/**
* Grand permissions for Content manager global role.
*/
function opigno_certificate_update_8001() {
// Allow platform-level content managers to administer certificates.
$role = Role::load('content_manager');
$role
->grantPermission('administer certificates');
$role
->grantPermission('add certificate entities');
$role
->grantPermission('delete certificate entities');
$role
->grantPermission('edit certificate entities');
$role
->grantPermission('access certificate overview');
$role
->grantPermission('view published certificate entities');
$role
->grantPermission('view unpublished certificate entities');
$role
->save();
}
/**
* Allow to edit WYSIWYG Certificate with CKEditor.
*/
function opigno_certificate_update_8002() {
$config_path = drupal_get_path('module', 'opigno_certificate') . '/config/install';
$storage = new FileStorage($config_path);
$config_storage = \Drupal::service('config.storage');
$data = $storage
->read('filter.format.opigno_certificate_wysiwyg');
$config_storage
->write('filter.format.opigno_certificate_wysiwyg', $data);
$data = $storage
->read('editor.editor.opigno_certificate_wysiwyg');
$config_storage
->write('editor.editor.opigno_certificate_wysiwyg', $data);
}
/**
* Allow to add background image to WYSIWYG Certificate with CKEditor.
*/
function opigno_certificate_update_80021() {
$config_path = drupal_get_path('module', 'opigno_certificate') . '/config/install';
$storage = new FileStorage($config_path);
$config_storage = \Drupal::service('config.storage');
$data = $storage
->read('filter.format.opigno_certificate_wysiwyg');
$config_storage
->write('filter.format.opigno_certificate_wysiwyg', $data);
$data = $storage
->read('editor.editor.opigno_certificate_wysiwyg');
$config_storage
->write('editor.editor.opigno_certificate_wysiwyg', $data);
}
/**
* Creates the paper_orientation field in opigno_certificate.
*/
function opigno_certificate_update_80022() {
$field = BaseFieldDefinition::create('list_string')
->setLabel(t('Paper Orientation'))
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setDefaultValue('portrait')
->setSetting('allowed_values', [
'portrait' => t('Portrait'),
'landscape' => t('Landscape'),
])
->setDisplayOptions('form', [
'type' => 'options_buttons',
'weight' => -5,
]);
$definition_manager = \Drupal::entityDefinitionUpdateManager();
$definition_manager
->installFieldStorageDefinition('paper_orientation', 'opigno_certificate', 'opigno_certificate', $field);
$config_path = drupal_get_path('module', 'opigno_certificate') . '/config/install';
$storage = new FileStorage($config_path);
$config_storage = \Drupal::service('config.storage');
$data = $storage
->read('core.entity_form_display.opigno_certificate.wysiwyg.default');
$config_storage
->write('core.entity_form_display.opigno_certificate.wysiwyg.default', $data);
}
/**
* Enables CKEditor Background module.
*/
function opigno_certificate_update_80023() {
\Drupal::service('module_installer')
->install([
'ckeditor_bgimage',
'ckeditor_font',
]);
}
/**
* Update text format for WYSIWYG Certificate with CKEditor.
*/
function opigno_certificate_update_80024() {
$config_path = drupal_get_path('module', 'opigno_certificate') . '/config/install';
$storage = new FileStorage($config_path);
$config_storage = \Drupal::service('config.storage');
$data = $storage
->read('filter.format.opigno_certificate_wysiwyg');
$config_storage
->write('filter.format.opigno_certificate_wysiwyg', $data);
$data = $storage
->read('editor.editor.opigno_certificate_wysiwyg');
$config_storage
->write('editor.editor.opigno_certificate_wysiwyg', $data);
}
/**
* Disable module view_mode_selector.
*/
function opigno_certificate_update_80025() {
\Drupal::service('module_installer')
->uninstall([
'view_mode_selector',
]);
}
Functions
Name | Description |
---|---|
opigno_certificate_install | Creates default certificate. |
opigno_certificate_update_8001 | Grand permissions for Content manager global role. |
opigno_certificate_update_8002 | Allow to edit WYSIWYG Certificate with CKEditor. |
opigno_certificate_update_80021 | Allow to add background image to WYSIWYG Certificate with CKEditor. |
opigno_certificate_update_80022 | Creates the paper_orientation field in opigno_certificate. |
opigno_certificate_update_80023 | Enables CKEditor Background module. |
opigno_certificate_update_80024 | Update text format for WYSIWYG Certificate with CKEditor. |
opigno_certificate_update_80025 | Disable module view_mode_selector. |