3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter;
5 use Drupal\drupalmoduleupgrader\ConverterBase;
6 use Drupal\drupalmoduleupgrader\TargetInterface;
7 use Drupal\drupalmoduleupgrader\Utility\StringTransformTrait;
12 * description = @Translation("Converts Drupal 7 blocks to plugins."),
14 * "hook_block_configure",
19 * fixme = @Translation("hook_!hook is gone in Drupal 8.
21 It has been left here by the Drupal Module Upgrader so that you can move its
22 logic into the appropriate block plugins, which should be in the
23 src/Plugin/Block directory. Once all logic is moved into the plugins, delete
26 * "https://www.drupal.org/node/1880620"
30 class Blocks extends ConverterBase {
32 use StringTransformTrait;
37 public function convert(TargetInterface $target) {
39 $blocks = $this->executeHook($target, 'block_info');
41 catch (\LogicException $e) {
42 $this->log->warning($e->getMessage(), [
43 'target' => $target->id(),
44 'hook' => $this->pluginDefinition['hook'],
49 $indexer = $target->getIndexer('function');
51 foreach ($blocks as $id => $info) {
52 // Render the block plugin's shell.
54 '#theme' => 'dmu_block',
55 '#module' => $target->id(),
56 '#class' => $this->toTitleCase(preg_replace('/[^a-zA-Z0-9_]+/', '_', $id)),
58 '#block_label' => $info['info'],
59 '#configurable' => $indexer->has('block_configure'),
61 $this->writeClass($target, $this->parse($render));
64 // Slap a FIXME on hook_block_info(), and on other block hooks which
65 // may or may not exist.
66 $this->addFixMe($target, 'block_info');
68 if ($indexer->has('hook_block_view')) {
69 $this->addFixMe($target, 'block_view');
71 if ($indexer->has('hook_block_save')) {
72 $this->addFixMe($target, 'block_save');
74 if ($indexer->has('hook_block_configure')) {
75 $this->addFixMe($target, 'block_configure');
80 * Slaps a translated FIXME notice above a block-related hook.
82 * @param TargetInterface $target
85 * The hook to put the FIXME on. It's up to the calling code to ensure
86 * that the hook actually exists.
88 private function addFixMe(TargetInterface $target, $hook) {
89 $variables = ['!hook' => $hook];
92 ->getIndexer('function')
93 ->get('hook_' . $hook)
94 ->setDocComment($this->buildFixMe(NULL, $variables, self::DOC_COMMENT));
96 $target->save($function);