public static function BlocksController::importBlocksForce in Structure Sync 8
Same name and namespace in other branches
- 2.x src/Controller/BlocksController.php \Drupal\structure_sync\Controller\BlocksController::importBlocksForce()
Function to import (create) all custom blocks that need to be imported.
1 call to BlocksController::importBlocksForce()
- BlocksController::importBlocks in src/
Controller/ BlocksController.php - Function to import custom blocks.
File
- src/
Controller/ BlocksController.php, line 401
Class
- BlocksController
- Controller for syncing custom blocks.
Namespace
Drupal\structure_sync\ControllerCode
public static function importBlocksForce($blocks, &$context) {
foreach ($blocks as $block) {
$blockContent = BlockContent::create([
'info' => $block['info'],
'langcode' => $block['langcode'],
'uuid' => $block['uuid'],
'type' => $block['bundle'],
]);
if (array_key_exists('fields', $block)) {
foreach ($block['fields'] as $fieldName => $fieldValue) {
$blockContent
->set($fieldName, $fieldValue);
}
}
$blockContent
->save();
if (array_key_exists('drush', $context) && $context['drush'] === TRUE) {
drush_log('Imported "' . $block['info'] . '"', 'ok');
}
StructureSyncHelper::logMessage('Imported "' . $block['info'] . '"');
}
}