From cd4c61e425f2958ec74f16e5a04432308726126b Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Sun, 9 Jun 2013 11:37:29 +0100 Subject: [PATCH] Issue #1898038 by jenlampton, joelpittet, duellj, Cottser, Shawn DeArmond, widukind, ezeedub, c4rl: Custom_block().module - Convert theme_ functions to Twig. --- .../block/custom_block/custom_block.module | 16 +---------- .../block/custom_block/custom_block.pages.inc | 27 +++++++------------ .../templates/custom-block-add-list.html.twig | 25 +++++++++++++++++ 3 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 core/modules/block/custom_block/templates/custom-block-add-list.html.twig diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index b8785dee4fd..9273cafde03 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -115,28 +115,14 @@ function custom_block_menu() { */ function custom_block_theme($existing, $type, $theme, $path) { return array( - 'custom_block_block' => array( - 'variables' => array('body' => NULL, 'format' => NULL), - ), 'custom_block_add_list' => array( 'variables' => array('content' => NULL), 'file' => 'custom_block.pages.inc', + 'template' => 'custom-block-add-list', ), ); } -/** - * Returns HTML for a custom block. - * - * @ingroup themeable - */ -function theme_custom_block_block($variables) { - $body = $variables['body']; - $format = $variables['format']; - - return check_markup($body, $format); -} - /** * Loads a custom block type. * diff --git a/core/modules/block/custom_block/custom_block.pages.inc b/core/modules/block/custom_block/custom_block.pages.inc index 9c802c4c8a2..297475c6163 100644 --- a/core/modules/block/custom_block/custom_block.pages.inc +++ b/core/modules/block/custom_block/custom_block.pages.inc @@ -10,32 +10,25 @@ use Drupal\custom_block\Plugin\Core\Entity\CustomBlock; use Symfony\Component\HttpFoundation\RedirectResponse; /** - * Returns HTML for a list of available custom block types for block creation. + * Prepares variables for a custom block type creation list templates. * - * @param $variables + * Default template: custom-block-add-list.html.twig. + * + * @param array $variables * An associative array containing: * - content: An array of block types. * * @see custom_block_add_page() - * - * @ingroup themeable */ -function theme_custom_block_add_list($variables) { - $content = $variables['content']; - $output = ''; - - if ($content) { - $output = '
'; - foreach ($content as $type) { - $output .= '
' . l($type->label(), 'block/add/' . $type->id()) . '
'; - $output .= '
' . filter_xss_admin($type->description) . '
'; - } - $output .= '
'; +function template_preprocess_custom_block_add_list(&$variables) { + $variables['types'] = array(); + foreach ($variables['content'] as $type) { + $variables['types'][$type->id] = array(); + $variables['types'][$type->id]['link'] = l($type->label(), 'block/add/' . $type->id()); + $variables['types'][$type->id]['description'] = filter_xss_admin($type->description); } - return $output; } - /** * Page callback: Presents the custom block creation form. * diff --git a/core/modules/block/custom_block/templates/custom-block-add-list.html.twig b/core/modules/block/custom_block/templates/custom-block-add-list.html.twig new file mode 100644 index 00000000000..2878da2a653 --- /dev/null +++ b/core/modules/block/custom_block/templates/custom-block-add-list.html.twig @@ -0,0 +1,25 @@ +{# +/** + * @file + * Default theme implementation to present a list of custom block types. + * + * Available variables: + * - types: A collection of all the available custom block types. + * Each block type contains the following: + * - link: A link to add a block of this type. + * - description: A description of this custom block type. + * + * @see template_preprocess() + * @see template_preprocess_custom_block_add_list() + * + * @ingroup themeable + */ +#} +{% spaceless %} +
+ {% for type in types %} +
{{ type.link }}
+
{{ type.description }}
+ {% endfor %} +
+{% endspaceless %}