Blocks.php in Drupal 7 to 8/9 Module Upgrader 8
File
src/Plugin/DMU/Converter/Blocks.php
View source
<?php
namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
use Drupal\drupalmoduleupgrader\ConverterBase;
use Drupal\drupalmoduleupgrader\TargetInterface;
use Drupal\drupalmoduleupgrader\Utility\StringTransformTrait;
class Blocks extends ConverterBase {
use StringTransformTrait;
public function convert(TargetInterface $target) {
foreach ($this->pluginDefinition['hook'] as $hook) {
try {
$blocks = $this
->executeHook($target, $hook);
} catch (\LogicException $e) {
$this->log
->warning($e
->getMessage(), [
'target' => $target
->id(),
'hook' => substr($hook, 5),
]);
}
}
$indexer = $target
->getIndexer('function');
foreach ($blocks as $id => $info) {
$render = [
'#theme' => 'dmu_block',
'#module' => $target
->id(),
'#class' => $this
->toTitleCase(preg_replace('/[^a-zA-Z0-9_]+/', '_', $id)),
'#block_id' => $id,
'#block_label' => $info['info'],
'#configurable' => $indexer
->has('block_configure'),
];
$this
->writeClass($target, $this
->parse($render));
}
$this
->addFixMe($target, 'block_info');
if ($indexer
->has('hook_block_view')) {
$this
->addFixMe($target, 'block_view');
}
if ($indexer
->has('hook_block_save')) {
$this
->addFixMe($target, 'block_save');
}
if ($indexer
->has('hook_block_configure')) {
$this
->addFixMe($target, 'block_configure');
}
}
private function addFixMe(TargetInterface $target, $hook) {
$variables = [
'@hook' => $hook,
];
$function = $target
->getIndexer('function')
->get('hook_' . $hook)
->setDocComment($this
->buildFixMe(NULL, $variables, self::DOC_COMMENT));
$target
->save($function);
}
}
Classes
Name |
Description |
Blocks |
Plugin annotation
@Converter(
id = "blocks",
description = @Translation("Converts Drupal 7 blocks to plugins."),
hook = {
"hook_block_configure",
"hook_block_info",
"hook_block_save",
"hook_block_view"
},
fixme =… |