Commit 236ecf36 authored by Aleksey.Alekseev's avatar Aleksey.Alekseev
Browse files

block import v1.0 + policy variable for page.html.twig and page--service.html.twig

parent 4a1e5855
......@@ -16,7 +16,7 @@ class DrushContentImport extends DrushCommands {
* Content directory.
*
* @command synhelper:content_import
* @usage synhelper:scont $directory
* @usage synhelper:scont $directory
* Full import from $directory.
*/
public function import($directory) {
......@@ -25,6 +25,22 @@ class DrushContentImport extends DrushCommands {
$this->output()->writeln("!NOTE Done.");
}
/**
* Synhelper Blocks import.
*
* @param string $directory
* Content directory.
*
* @command synhelper:block_import
* @usage synhelper:scont $directory
* Blocks import from $directory/block.
*/
public function importBlocks($directory) {
$this->output()->writeln("Import Blocks from: $directory/block");
\Drupal::service('synhelper.content_import')->importBlocks($directory);
$this->output()->writeln("!NOTE Done.");
}
/**
* Synhelper Taxonomy import.
*
......@@ -32,7 +48,7 @@ class DrushContentImport extends DrushCommands {
* Content directory.
*
* @command synhelper:taxonomy_import
* @usage synhelper:scont $directory
* @usage synhelper:scont $directory
* Taxonomy import from $directory/taxonomy.
*/
public function importTaxonomy($directory) {
......@@ -48,7 +64,7 @@ class DrushContentImport extends DrushCommands {
* Content directory.
*
* @command synhelper:product_import
* @usage synhelper:scont $directory
* @usage synhelper:scont $directory
* Products import from $directory/products.
*/
public function importProducts($directory) {
......@@ -64,7 +80,7 @@ class DrushContentImport extends DrushCommands {
* Content directory.
*
* @command synhelper:menu_import
* @usage synhelper:scont $directory
* @usage synhelper:scont $directory
* Menu import from $directory/menu.
*/
public function importMenu($directory) {
......@@ -80,7 +96,7 @@ class DrushContentImport extends DrushCommands {
* Content directory.
*
* @command synhelper:contacts_import
* @usage synhelper:scont $directory
* @usage synhelper:scont $directory
* Contacts import from $directory/contacts.
*/
public function importContacts($directory) {
......@@ -96,7 +112,7 @@ class DrushContentImport extends DrushCommands {
* Content directory.
*
* @command synhelper:node_import
* @usage synhelper:scont $directory
* @usage synhelper:scont $directory
* Nodes import from $directory/nodes.
*/
public function importNode($directory) {
......@@ -112,7 +128,7 @@ class DrushContentImport extends DrushCommands {
* Content directory.
*
* @command synhelper:synlanding_config_import
* @usage synhelper:scont $directory
* @usage synhelper:scont $directory
* Synlanding Config import from $directory/synlanding.
*/
public function setSynLandingConfig($directory) {
......
<?php
namespace Drupal\synhelper\Hook;
/**
* PreprocessPage.
*/
class PreprocessPage {
/**
* Hook.
*/
public static function hook(&$variables) {
$config = \Drupal::config('synhelper.settings');
if ($config->get('fz152')) {
$variables['footer_policy'] = TRUE;
}
}
}
......@@ -36,6 +36,40 @@ class SynhelperContentImport {
$this->setSynLandingConfig($directory);
}
/**
* Import Blocks.
*/
public function importBlocks(string $directory) {
$sourceBlock = new FileStorage($directory . '/block');
foreach ($sourceBlock->listAll() as $file) {
$data = $sourceBlock->read($file);
$storage = \Drupal::entityTypeManager()->getStorage('block_content');
foreach ($data as $key => $value) {
switch ($key) {
case 'field_image':
case 'field_gallery':
$b[$key] = $this->importImages($value);
break;
case 'field_attach':
$b[$key] = $this->importAttach($value);
break;
case 'field_paragraph':
$b[$key] = $this->importParagraph($value);
break;
default:
$b[$key] = $value;
break;
}
}
$b['uid'] = 1;
$block = $storage->create($b);
$block->save();
}
}
/**
* Import Taxonomy.
*/
......
......@@ -5,3 +5,7 @@ core: 8.x
core_version_requirement: ^8 || ^9
# version: 1.0
package: Synapse
# Information added by Drupal.org packaging script on 2021-08-27
version: '8.x-1.44'
project: 'synhelper'
datestamp: 1630053286
......@@ -8,6 +8,7 @@
use Drupal\synhelper\Hook\ModulesInstalled;
use Drupal\synhelper\Hook\ContactMessagePresave;
use Drupal\synhelper\Hook\PreprocessHtml;
use Drupal\synhelper\Hook\PreprocessPage;
use Drupal\synhelper\Hook\FileValidate;
use Drupal\synhelper\Hook\FormContactMailSettingsAlter;
use Drupal\synhelper\Hook\FormContactMessageFormAlter;
......@@ -23,6 +24,20 @@ use Drupal\synhelper\Hook\FormNodeFormAlter;
use Drupal\synhelper\Hook\FormCommerceCheckoutFlowMultistepDefaultAlter;
use Drupal\Core\Form\FormStateInterface;
/**
* Prepares variables for the page--service.html.twig template.
*/
function synhelper_preprocess_page__service(&$variables) {
PreprocessPage::hook($variables);
}
/**
* Prepares variables for the page.html.twig template.
*/
function synhelper_preprocess_page(&$variables) {
PreprocessPage::hook($variables);
}
/**
* Implements hook_modules_installed().
*/
......@@ -86,6 +101,7 @@ function synhelper_contact_message_presave($entity) {
ContactMessagePresave::setTitle($entity);
}
/**
* Implements hook_preprocess_html().
*/
......@@ -93,6 +109,7 @@ function synhelper_preprocess_html(&$variables) {
PreprocessHtml::hook($variables);
}
/**
* Implements hook_file_validate().
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment