Skip to content

Commit 19d096b

Browse files
authored
Merge pull request #5 from dof-dss/development
Release to main
2 parents 8e3b562 + 7b250f6 commit 19d096b

17 files changed

+364
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#drupal-off-canvas ul.unity-landing-pages li {
2+
padding-bottom: 0;
3+
}
4+
5+
#drupal-off-canvas a.unity-landing-page--button-back {
6+
border: 1px solid #fff;
7+
width: 100%;
8+
height: auto;
9+
display: block;
10+
margin: 0 0 10px 0;
11+
padding: 10px 16px;
12+
color: white;
13+
}
14+
15+
#drupal-off-canvas li a.unity-landing-pages--add-section,
16+
#drupal-off-canvas li a.unity-landing-pages--add-block {
17+
padding: 20px 0;
18+
width: 100%;
19+
text-align: center;
20+
margin: 10px 0 0 0;
21+
background-color: #555;
22+
color: white;
23+
text-decoration: none;
24+
}
25+
26+
#drupal-off-canvas li a.unity-landing-pages--add-section > *,
27+
#drupal-off-canvas li a.unity-landing-pages--add-block > * {
28+
text-decoration: none;
29+
background-color: transparent;
30+
}
31+
32+
#drupal-off-canvas a.unity-landing-pages--add-section:hover,
33+
#drupal-off-canvas a.unity-landing-pages--add-block:hover {
34+
text-decoration: none;
35+
background-color: #0a78cd;
36+
}
37+
38+
.layout-builder-add-block .form-item-settings-admin-label label {
39+
display: none;
40+
}
41+
42+
.layout-builder-add-block .form-item-settings-admin-label {
43+
font-size: 1.5em;
44+
}
45+
46+
.layout-builder-add-block .field--type-link .field-multiple-table th,
47+
.layout-builder-add-block .field--type-block-field th {
48+
background: #dbdbdb;
49+
}
50+
51+
.layout-builder-add-block .field--type-link .field-multiple-table th h4,
52+
.layout-builder-add-block .field--type-entity-reference-revisions .field-multiple-table th h4,
53+
.layout-builder-add-block .field--type-block-field th h4 {
54+
color: white;
55+
margin: 0;
56+
}
57+
58+
#layout-builder .layout-builder__link--add {
59+
padding-left: 25px !important;
60+
}
Loading
Loading
319 Bytes
Loading
Loading
359 Bytes
Loading
359 Bytes
Loading
407 Bytes
Loading
Loading
1.32 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
3+
namespace Drupal\unity_landing_pages\Controller;
4+
5+
use Drupal\layout_builder\Controller\ChooseBlockController;
6+
use Drupal\layout_builder\SectionStorageInterface;
7+
use Symfony\Component\DependencyInjection\ContainerInterface;
8+
9+
/**
10+
* Controller to alter display of Layout builder Block form.
11+
*/
12+
class LandingPagesChooseBlockController extends ChooseBlockController {
13+
/**
14+
* The module handler service.
15+
*
16+
* @var \Drupal\Core\Extension\ModuleHandler
17+
*/
18+
protected $moduleHandler;
19+
20+
/**
21+
* The file system service.
22+
*
23+
* @var \Drupal\Core\File\FileSystem
24+
*/
25+
protected $fileSystem;
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public static function create(ContainerInterface $container) {
31+
$instance = parent::create($container);
32+
$instance->moduleHandler = $container->get('module_handler');
33+
$instance->fileSystem = $container->get('file_system');
34+
return $instance;
35+
}
36+
37+
/**
38+
* Provides the UI for choosing a new inline block-icons.
39+
*
40+
* Improves upon the core layout builder display by adding block-icons type
41+
* icons and additional styling for the back link.
42+
*
43+
* @param \Drupal\layout_builder\SectionStorageInterface $section_storage
44+
* The section storage.
45+
* @param int $delta
46+
* The delta of the section to splice.
47+
* @param string $region
48+
* The region the block-icons is going in.
49+
*
50+
* @return array
51+
* A render array.
52+
*/
53+
public function inlineBlockList(SectionStorageInterface $section_storage, $delta, $region) {
54+
$build = parent::inlineBlockList($section_storage, $delta, $region);
55+
$module_path_rel = drupal_get_path('module', 'unity_landing_pages');
56+
$module_path_abs = $this->fileSystem->realpath($module_path_rel);
57+
58+
// Support for Layout Builder Restrictions.
59+
if ($this->moduleHandler->moduleExists('layout_builder_restrictions')) {
60+
$layout_builder_restrictions_manager = \Drupal::service('plugin.manager.layout_builder_restriction');
61+
$restriction_plugins = $layout_builder_restrictions_manager->getSortedPlugins();
62+
foreach (array_keys($restriction_plugins) as $id) {
63+
$plugin = $layout_builder_restrictions_manager->createInstance($id);
64+
$allowed_inline_blocks = $plugin->inlineBlocksAllowedinContext($section_storage, $delta, $region);
65+
66+
foreach ($build['links']['#links'] as $key => $link) {
67+
$route_parameters = $link['url']->getRouteParameters();
68+
if (!in_array($route_parameters['plugin_id'], $allowed_inline_blocks)) {
69+
unset($build['links']['#links'][$key]);
70+
}
71+
}
72+
}
73+
}
74+
75+
foreach ($build['links']['#links'] as &$link) {
76+
$id = $link['url']->getRouteParameters()['plugin_id'];
77+
$img_name = substr($id, (strpos($id, ':') + 1));
78+
$title = $link['title'];
79+
80+
// Check for an image matching this block otherwise use the default.
81+
if (file_exists($module_path_abs . '/img/block-icons/' . $img_name . '.png')) {
82+
$img_path = $module_path_rel . '/img/block-icons/' . $img_name . '.png';
83+
}
84+
else {
85+
$img_path = $module_path_rel . '/img/block-icons/default.png';
86+
}
87+
88+
$icon = [
89+
'#theme' => 'image',
90+
'#uri' => $img_path,
91+
'#width' => 150,
92+
'#height' => 150,
93+
'#alt' => $title,
94+
];
95+
96+
// Convert the title to a nested set of HTML elements.
97+
$link['title'] =
98+
[
99+
$icon,
100+
[
101+
'#type' => 'container',
102+
'#children' => $title,
103+
],
104+
];
105+
$link['attributes']['class'][] = 'unity-landing-pages--add-block';
106+
}
107+
108+
// Additional styling for the back link.
109+
$build['back_button']['#attributes']['class'][] = 'unity-landing-page--button-back';
110+
111+
// Add sidebar title.
112+
$build['#title'] = $this->t('Select a custom block type');
113+
114+
$build['links']['#attributes']['class'][] = 'unity-landing-pages';
115+
116+
$build['#attached']['library'][] = 'unity_landing_pages/landing_page_admin';
117+
118+
return $build;
119+
}
120+
121+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Drupal\unity_landing_pages\Controller;
4+
5+
use Drupal\layout_builder\Controller\ChooseSectionController;
6+
use Drupal\layout_builder\SectionStorageInterface;
7+
8+
/**
9+
* Controller to alter display of Layout builder Sections form.
10+
*/
11+
class LandingPagesChooseSectionController extends ChooseSectionController {
12+
13+
/**
14+
* Choose a layout plugin to add as a section.
15+
*
16+
* Improves upon the core layout builder display by adding additional
17+
* styling for layouts and the back link.
18+
*
19+
* @param \Drupal\layout_builder\SectionStorageInterface $section_storage
20+
* The section storage.
21+
* @param int $delta
22+
* The delta of the section to splice.
23+
*
24+
* @return array
25+
* The render array.
26+
*/
27+
public function build(SectionStorageInterface $section_storage, $delta) {
28+
$build = parent::build($section_storage, $delta);
29+
30+
foreach ($build['layouts']['#items'] as &$item) {
31+
$item['#attributes']['class'][] = 'unity-landing-pages--add-section';
32+
}
33+
34+
// Add sidebar title.
35+
$build['#title'] = $this->t('Select a layout');
36+
37+
$build['layouts']['#attributes']['class'][] = 'unity-landing-pages';
38+
39+
$build['#attached']['library'][] = 'unity_landing_pages/landing_page_admin';
40+
41+
return $build;
42+
}
43+
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Drupal\unity_landing_pages\Routing;
4+
5+
use Drupal\Core\Routing\RouteSubscriberBase;
6+
use Symfony\Component\Routing\RouteCollection;
7+
8+
/**
9+
* Class LandingPagesRouteSubscriber.
10+
*
11+
* Listens to the dynamic route events.
12+
*/
13+
class LandingPagesRouteSubscriber extends RouteSubscriberBase {
14+
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected function alterRoutes(RouteCollection $collection) {
19+
if ($route = $collection->get('layout_builder.choose_section')) {
20+
$route->setDefaults([
21+
'_controller' => '\Drupal\unity_landing_pages\Controller\LandingPagesChooseSectionController::build',
22+
]);
23+
}
24+
25+
if ($route = $collection->get('layout_builder.choose_inline_block')) {
26+
$route->setDefaults([
27+
'_controller' => '\Drupal\unity_landing_pages\Controller\LandingPagesChooseBlockController::inlineBlockList',
28+
]);
29+
}
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: 'Unity Landing Pages'
2+
type: module
3+
description: 'Unity Landing Page functions and overrides'
4+
core_version_requirement: ^8.8 || ^9
5+
package: 'Unity'
6+
dependencies:
7+
- drupal:layout_builder
8+
- drupal:block
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
landing_page_admin:
2+
css:
3+
theme:
4+
css/landing_page_admin.css: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Contains nidirect_landing_pages.module.
6+
*/
7+
8+
use Drupal\Core\Form\FormStateInterface;
9+
10+
/**
11+
* Implements hook_ENTITY_TYPE_form_alter().
12+
*/
13+
function unity_landing_pages_form_alter(&$form, FormStateInterface $form_state, $form_id) {
14+
if ($form_id === 'layout_builder_add_block' || $form_id === 'layout_builder_update_block') {
15+
16+
// Add process callback that will allow us to alter block form element rendering.
17+
if (!empty($form['settings']['block_form'])) {
18+
$form['settings']['block_form']['#process'][] = '_unity_landing_pages_block_form_alter';
19+
}
20+
21+
// Depending on block name, set the title and hide it or prevent authors hiding it.
22+
if (!empty($form['settings']['block_form']['#block'])) {
23+
$block_name = $form['settings']['block_form']['#block']->bundle();
24+
switch ($block_name) {
25+
case 'banner_deep':
26+
case 'card_contact':
27+
case 'card_deck_plain':
28+
case 'video':
29+
case 'text':
30+
// The title defaults to the block type name and is not displayed.
31+
$form['settings']['label']['#default_value'] = $block_name;
32+
$form['settings']['label']['#type'] = 'hidden';
33+
$form['settings']['label_display']['#default_value'] = FALSE;
34+
$form['settings']['label_display']['#access'] = FALSE;
35+
break;
36+
37+
case 'card_standard':
38+
case 'card_wide':
39+
case 'card_plain':
40+
// The title must be displayed.
41+
$form['settings']['label_display']['#default_value'] = TRUE;
42+
$form['settings']['label_display']['#access'] = FALSE;
43+
break;
44+
45+
}
46+
}
47+
}
48+
49+
// Hide the listing fields as they may now only be edited in layout builder.
50+
if (($form_id == 'node_landing_page_form') || ($form_id == 'node_landing_page_edit_form')) {
51+
$form['field_manually_control_listing']['#access'] = FALSE;
52+
$form['field_listing']['#access'] = FALSE;
53+
}
54+
}
55+
56+
/**
57+
* Process callback for landing page custom block forms.
58+
*/
59+
function _unity_landing_pages_block_form_alter(array $element, FormStateInterface $form_state) {
60+
61+
if (!empty($element['#block']) && $element['#block']->bundle() === 'card_contact') {
62+
// Remove container-inline class from the telephone plus fieldsets.
63+
if (!empty($element['field_telephone']) && !empty($element['field_telephone']['widget'])) {
64+
$classes = &$element['field_telephone']['widget'][0]['#attributes']['class'];
65+
$classes = array_filter($classes, function ($e) {
66+
return $e != 'container-inline';
67+
});
68+
}
69+
}
70+
71+
// Change teaser fields to a textarea.
72+
if (!empty($element['field_teaser']) && !empty($element['field_teaser']['widget'])) {
73+
$element['field_teaser']['widget'][0]['value']['#type'] = 'textarea';
74+
$element['field_teaser']['widget'][0]['value']['#attributes']['rows'] = 3;
75+
$element['field_teaser']['widget'][0]['value']['#attributes']['cols'] = 60;
76+
}
77+
78+
return $element;
79+
}
80+
81+
/**
82+
* Implements hook_preprocess_page().
83+
*/
84+
function unity_landing_pages_preprocess_page(&$variables) {
85+
// Add custom CSS to the initial layout builder page.
86+
if (\Drupal::routeMatch()->getRouteName() == 'layout_builder.overrides.node.view') {
87+
$variables['#attached']['library'][] = 'unity_landing_pages/landing_page_admin';
88+
}
89+
}
90+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
unity_landing_pages.route_subscriber:
3+
class: Drupal\unity_landing_pages\Routing\LandingPagesRouteSubscriber
4+
tags:
5+
- { name: event_subscriber }

0 commit comments

Comments
 (0)