sharerich.install in Sharerich 8
Same filename and directory in other branches
Install, update, and uninstall functions for the sharerich module.
File
sharerich.installView source
<?php
/**
* @file
* Install, update, and uninstall functions for the sharerich module.
*/
use Drupal\block\Entity\Block;
/**
* Implements hook_install().
*/
function sharerich_install() {
$default_theme = \Drupal::config('system.theme')
->get('default');
// Create default block.
Block::create(array(
'id' => 'sharerich_block',
'label' => t('Share this'),
'type' => 'sharerich',
'theme' => $default_theme,
'region' => 'content',
'weight' => -10,
'provider' => NULL,
'plugin' => 'sharerich',
'settings' => array(
'id' => 'sharerich_block',
'label' => t('Share this'),
'provider' => 'sharerich',
'label_display' => 'visible',
'sharerich_set' => 'default',
'orientation' => 'vertical',
'sticky' => TRUE,
),
))
->save();
}
/**
* Migrate sharerich sets and blocks.
*/
function sharerich_update_8300() {
$query = \Drupal::database()
->select('config', 'c');
$query
->addField('c', 'name');
$query
->addField('c', 'data');
$query
->condition('data', '%sharerich%', 'LIKE');
$result = $query
->execute();
$records = $result
->fetchAll();
foreach ($records as $item) {
if (substr($item->name, 0, 11) == 'block.block') {
// Migrate blocks.
$data = unserialize($item->data);
if ($data['plugin'] == 'sharerich_block') {
$data['plugin'] = 'sharerich';
$data['settings']['id'] = $data['id'];
\Drupal::database()
->update('config')
->condition('name', $item->name)
->fields([
'data' => serialize($data),
])
->execute();
}
}
if (substr($item->name, 0, 19) == 'sharerich.sharerich') {
// Migrate sharerich sets.
\Drupal::database()
->update('config')
->condition('name', $item->name)
->fields([
'name' => str_replace('sharerich.sharerich', 'sharerich.set', $item->name),
])
->execute();
}
}
}
/**
* Implements hook_uninstall().
*/
function sharerich_uninstall() {
}
Functions
Name | Description |
---|---|
sharerich_install | Implements hook_install(). |
sharerich_uninstall | Implements hook_uninstall(). |
sharerich_update_8300 | Migrate sharerich sets and blocks. |