You are here

layouter.module in Layouter - WYSIWYG layout templates 8

Same filename and directory in other branches
  1. 7 layouter.module

Contains hooks implementations, prerender callback and common functions.

File

layouter.module
View source
<?php

/**
 * @file
 * Contains hooks implementations, prerender callback and common functions.
 */
use Drupal\Core\Url;
use Drupal\Component\Serialization\Json;
use Drupal\layouter\LayouterTextFormat;

/**
 * Implements hook_theme().
 */
function layouter_theme($existing, $type, $theme, $path) {
  return [
    'layouter_image_only' => [
      'variables' => [
        'image' => NULL,
      ],
      'template' => 'image_only',
    ],
    'layouter_two_columns' => [
      'variables' => [
        'text' => NULL,
      ],
      'template' => 'two_columns',
    ],
    'layouter_two_columns_img_left_text_right' => [
      'variables' => [
        'text' => NULL,
        'image' => NULL,
        'caption' => NULL,
      ],
      'template' => 'two_columns_img_left_text_right',
    ],
    'layouter_two_columns_img_right_text_left' => [
      'variables' => [
        'text' => NULL,
        'image' => NULL,
        'caption' => NULL,
      ],
      'template' => 'two_columns_img_right_text_left',
    ],
    'layouter_two_columns_text_img_left' => [
      'variables' => [
        'text' => NULL,
        'image' => NULL,
      ],
      'template' => 'two_columns_text_img_left',
    ],
    'layouter_big_img_text_below' => [
      'variables' => [
        'text' => NULL,
        'image' => NULL,
      ],
      'template' => 'big_img_text_below',
    ],
    'layouter_big_img_text_above' => [
      'variables' => [
        'text' => NULL,
        'image' => NULL,
      ],
      'template' => 'big_img_text_above',
    ],
    'layouter_big_img_two_column_text_below' => [
      'variables' => [
        'text' => NULL,
        'image' => NULL,
      ],
      'template' => 'big_img_two_column_text_below',
    ],
    'layouter_big_img_two_column_text_above' => [
      'variables' => [
        'text' => NULL,
        'image' => NULL,
      ],
      'template' => 'big_img_two_column_text_above',
    ],
  ];
}

/**
 * Implements hook_layouter_templates_info().
 */
function layouter_layouter_templates_info() {
  $templates = [
    'image_only' => [
      'title' => t('One image only'),
      'fields' => [
        'image' => [
          'type' => 'image',
          'title' => t('One image'),
          'description' => t('Image will be align left.'),
        ],
      ],
      'theme' => 'layouter_image_only',
    ],
    'two_columns' => [
      'title' => t('Two columns of continuous text'),
      'fields' => [
        'text' => [
          'type' => 'text',
          'title' => t('Two column text'),
          'description' => t('Text will be divided on two columns.'),
        ],
      ],
      'theme' => 'layouter_two_columns',
    ],
    'two_columns_img_left_text_right' => [
      'title' => t('Two columns with an image (with an optional description) on the left side and a text on the right'),
      'fields' => [
        'text' => [
          'type' => 'text',
          'description' => t('Text will be will be placed on the right column.'),
        ],
        'image' => [
          'type' => 'image',
        ],
        'caption' => [
          'type' => 'text',
          'title' => t('Caption'),
        ],
      ],
      'theme' => 'layouter_two_columns_img_left_text_right',
    ],
    'two_columns_img_right_text_left' => [
      'title' => t('Two columns with an image (with an optional description) on the right side and a text on the left'),
      'fields' => [
        'text' => [
          'type' => 'text',
        ],
        'image' => [
          'type' => 'image',
        ],
        'caption' => [
          'type' => 'text',
          'title' => t('Caption'),
        ],
      ],
      'theme' => 'layouter_two_columns_img_right_text_left',
    ],
    'two_columns_text_img_left' => [
      'title' => t('Two columns of continuous text with an image on top left'),
      'fields' => [
        'text' => [
          'type' => 'text',
        ],
        'image' => [
          'type' => 'image',
        ],
      ],
      'theme' => 'layouter_two_columns_text_img_left',
    ],
    'big_img_text_below' => [
      'title' => t('Big image on top with a text below'),
      'fields' => [
        'text' => [
          'type' => 'text',
        ],
        'image' => [
          'type' => 'image',
        ],
      ],
      'theme' => 'layouter_big_img_text_below',
    ],
    'big_img_text_above' => [
      'title' => t('Big image at bottom with a text above'),
      'fields' => [
        'text' => [
          'type' => 'text',
        ],
        'image' => [
          'type' => 'image',
        ],
      ],
      'theme' => 'layouter_big_img_text_above',
    ],
    'big_img_two_column_text_below' => [
      'title' => t('Big image on top with a two columns of text below'),
      'fields' => [
        'text' => [
          'type' => 'text',
        ],
        'image' => [
          'type' => 'image',
        ],
      ],
      'theme' => 'layouter_big_img_two_column_text_below',
    ],
    'big_img_two_column_text_above' => [
      'title' => t('Big image at bottom with a two columns of text above'),
      'fields' => [
        'text' => [
          'type' => 'text',
        ],
        'image' => [
          'type' => 'image',
        ],
      ],
      'theme' => 'layouter_big_img_two_column_text_above',
    ],
  ];
  return $templates;
}

/**
 * Implements hook_element_info_alter().
 */
function layouter_element_info_alter(array &$types) {
  if (\Drupal::currentUser()
    ->hasPermission('use layouter')) {
    $types['text_format']['#pre_render'][] = [
      LayouterTextFormat::class,
      'preRender',
    ];
  }
}