Skip to content
Snippets Groups Projects
Commit a33e4883 authored by Viktor Holovachek's avatar Viktor Holovachek
Browse files

Issue #3421054 - Drupal 10

parent b77984ae
No related branches found
No related tags found
1 merge request!3Issue #3421054 - Drupal 10
Pipeline #95739 passed
# Block Theme
== Description ==
BlockTheme allows an admin to define tpl files for standard block templates
and provides a select box on the block configure form so the user can select
a tpl file to use as opposed to having to override the templates by block ID.
== Installation ==
For a full description of the module, visit the
[project page](https://www.drupal.org/project/blocktheme).
To submit bug reports and feature suggestions, or track changes in the
[issue queue](https://www.drupal.org/project/issues/blocktheme).
## Table of contents
- Requirements
- Installation
- Configuration
- Maintainers
## Requirements
This module requires no modules outside of Drupal core.
## Installation
Install as you would normally install a contributed Drupal module. For further
information, see
[Installing Drupal Modules](https://www.drupal.org/docs/extending-drupal/installing-drupal-modules).
## Configuration
1. Enable the module
2. Go to admin/config/blocktheme and add entries like:
2. Go to /admin/structure/block/blocktheme and add entries like:
customtemplate|My Custom Template
mysupertemplate|My SuperTemplate
Where the first name is the machine-readable name of your template which may contain only
......@@ -30,6 +57,11 @@ in the selectionbox on the block edit form.
$blocktheme_vars variable. This array contains custom variables defined in the
block edit form, right below the block theme selection.
== Usage ==
Go to the edit form for any block and select the appropriate template.
## Maintainers
- Andrei Mateescu - [amateescu](https://www.drupal.org/u/amateescu)
- Greg Harvey - [greg.harvey](https://www.drupal.org/u/gregharvey)
- Jacob Singh - [JacobSingh](https://www.drupal.org/u/jacobsingh)
- Alexander Shudra - [str8](https://www.drupal.org/u/str8)
- Viktor Holovachek - [AstonVictor](https://www.drupal.org/u/astonvictor)
......@@ -2,4 +2,5 @@ name: 'Block Theme'
type: module
description: 'Provides a configuration option to select custom themes for blocks'
core_version_requirement: ^8.8 || ^9 || ^10
configure: admin_blocktheme_config
package: 'Block'
configure: blocktheme.settings
blocktheme.settings:
title: 'Manage block theme settings'
route_name: blocktheme.settings
parent: block.admin_display
blocktheme.settings:
route_name: blocktheme.settings
title: 'Manage block theme settings'
base_route: block.admin_display
......@@ -18,17 +18,9 @@ use Drupal\Core\Url;
* Implements hook_help().
*/
function blocktheme_help($route_name, RouteMatchInterface $route_match) {
$output = '';
switch ($route_match->getRouteName()) {
case 'admin_blocktheme_config':
$output .= t('BlockTheme allows an admin to define twig files for standard block templates and provides a select box on the block configure form so the user can select a twig file to use as opposed to having to override the templates by block ID.');
break;
}
switch ($route_name) {
case 'help.page.blocktheme':
$output .= t('Allows the admin to define re-usable block templates that can be configured from block config screen.');
$output = t('Allows the admin to define re-usable block templates that can be configured from block config screen.');
$items = [];
$items[] = Link::fromTextAndUrl(t('Block Theme'), Url::fromRoute('admin_blocktheme_config'));
$output .= '<h3>' . t('Block Theme administration pages') . '</h3>';
......@@ -37,11 +29,8 @@ function blocktheme_help($route_name, RouteMatchInterface $route_match) {
'#items' => $items,
];
$output .= \Drupal::service('renderer')->render($item_list);
break;
return $output;
}
return $output;
}
/**
......@@ -139,8 +128,7 @@ function blocktheme_form_basic_block_content_form_alter(&$form, FormStateInterfa
* Add new column with name of template to the blocks list page.
*/
function blocktheme_form_block_admin_display_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$config = \Drupal::config('blocktheme.settings')
->get('blocktheme_show_custom_block_theme');
$config = \Drupal::config('blocktheme.settings')->get('show');
if (!empty($config)) {
$form['blocks']['#header'][] = t('Custom theme');
foreach ($form['blocks'] as $block => $parametrs) {
......@@ -166,10 +154,10 @@ function blocktheme_form_block_admin_display_form_alter(&$form, FormStateInterfa
*/
function blocktheme_set($blocktheme, $blocktheme_vars = NULL) {
$config = \Drupal::configFactory()->getEditable('blocktheme.settings');
$config->set('blocktheme', $blocktheme)->save();
$config->set('themes', $blocktheme)->save();
if ($blocktheme_vars !== NULL) {
$config->set('blocktheme_vars', $blocktheme_vars)->save();
$config->set('variables', $blocktheme_vars)->save();
}
}
......@@ -180,14 +168,14 @@ function blocktheme_get() {
static $blocktheme;
$config = \Drupal::config('blocktheme.settings');
if (empty($blocktheme)) {
$blocktheme = $config->get('blocktheme');
$blocktheme = $config->get('themes');
if (is_null($blocktheme)) {
$blocktheme = [];
}
}
return $blocktheme;
return array_filter((array) $blocktheme);
}
/**
......@@ -197,14 +185,14 @@ function blocktheme_get_vars() {
static $blocktheme_vars;
$config = \Drupal::config('blocktheme.settings');
if (empty($blocktheme_vars)) {
$blocktheme_vars = $config->get('blocktheme_vars');
$blocktheme_vars = $config->get('variables');
if (is_null($blocktheme_vars)) {
$blocktheme_vars = [];
}
}
return $blocktheme_vars;
return array_filter((array) $blocktheme_vars);
}
/**
......@@ -257,7 +245,7 @@ function blocktheme_save($form, FormStateInterface $form_state) {
function blocktheme_get_blockthemes() {
$options = [];
$config = \Drupal::config('blocktheme.settings');
$blockthemes = $config->get('blocktheme_themes');
$blockthemes = $config->get('templates');
$options[] = t('- None -');
if ($blockthemes) {
......
admin_blocktheme_config:
path: '/admin/config/blocktheme'
blocktheme.settings:
path: '/admin/structure/block/blocktheme'
defaults:
_form: '\Drupal\blocktheme\Form\BlockthemeAdminSettingsForm'
_title: 'Manage block theme settings'
requirements:
_permission: 'administer menu'
_permission: 'administer blocks'
{
"name": "drupal/blocktheme",
"description": "BlockTheme allows an admin to define tpl files for standard block templates.",
"type": "drupal-module",
"license": "GPL-2.0-or-later",
"keywords": ["Drupal"],
"homepage": "https://www.drupal.org/project/blocktheme",
"authors": [
{
"name": "Andrei Mateescu (amateescu)",
"homepage": "https://www.drupal.org/u/amateescu",
"role": "Maintainer"
},
{
"name": "Greg Harvey (greg.harvey)",
"homepage": "https://www.drupal.org/u/gregharvey",
"role": "Maintainer"
},
{
"name": "Jacob Singh (JacobSingh)",
"homepage": "https://www.drupal.org/u/jacobsingh",
"role": "Maintainer"
},
{
"name": "Alexander Shudra (str8)",
"homepage": "https://www.drupal.org/u/str8",
"role": "Maintainer"
},
{
"name": "Viktor Holovachek (AstonVictor)",
"homepage": "https://www.drupal.org/u/astonvictor",
"role": "Maintainer"
}
],
"minimum-stability": "dev",
"support": {
"issues": "https://www.drupal.org/project/issues/blocktheme",
"source": "https://git.drupalcode.org/project/blocktheme"
},
"require": { }
}
blocktheme: ''
blocktheme_themes: ''
blocktheme_vars: ''
blocktheme_show_custom_block_theme: ''
\ No newline at end of file
show: false
blocktheme.settings:
type: config_object
label: 'Block theme settings'
mapping:
templates:
type: string
label: 'Custom Block Templates'
show:
type: boolean
label: 'Show Custom Block Theme'
themes:
type: sequence
label: 'Block themes'
sequence:
type: string
variables:
type: sequence
......@@ -68,21 +68,24 @@ class BlockthemeAdminSettingsForm extends ConfigFormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('blocktheme.settings');
$form['blocktheme_themes'] = [
$form['help'] = [
'#markup' => t('BlockTheme allows an admin to define twig files for standard block templates and provides a select box on the block configure form so the user can select a twig file to use as opposed to having to override the templates by block ID.'),
];
$form['templates'] = [
'#type' => 'textarea',
'#title' => $this->t('Custom Block Templates'),
'#description' => $this->t('Enter one value per row in the form: <em>customtemplate|Friendly Name</em>, where "customtemplate" corresponds to a twig file called <em>block--blocktheme--customtemplate.html.twig</em> as well as to the value of an extra variable <em>blocktheme</em> in the block template.'),
'#default_value' => $config->get('blocktheme_themes'),
'#wysiwyg' => FALSE,
'#default_value' => $config->get('templates'),
];
$form['blocktheme_show_custom_block_theme'] = [
$form['show'] = [
'#type' => 'checkbox',
'#default_value' => $config->get('blocktheme_show_custom_block_theme'),
'#title' => $this->t('Show Custom Block Theme'),
'#description' => $this->t('Show the custom block theme used for a block in the %block_admin_page.', [
'%block_admin_page' => Link::fromTextAndUrl('block admin page', Url::fromRoute('block.admin_display'))->toString(),
]),
'#default_value' => $config->get('show'),
];
return parent::buildForm($form, $form_state);
......@@ -93,8 +96,8 @@ class BlockthemeAdminSettingsForm extends ConfigFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('blocktheme.settings')
->set('blocktheme_themes', $form_state->getValue('blocktheme_themes'))
->set('blocktheme_show_custom_block_theme', $form_state->getValue('blocktheme_show_custom_block_theme'))
->set('templates', $form_state->getValue('templates'))
->set('show', (bool) $form_state->getValue('show'))
->save();
parent::submitForm($form, $form_state);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment