Skip to content
Snippets Groups Projects
Commit 32a18969 authored by Joshua Sedler's avatar Joshua Sedler :cartwheel_tone2: Committed by Julian Pustkuchen
Browse files

Issue #3263061 by Anybody, Grevil: [PP-1] Code style cleanup, Schema check, Basic Tests

parent bfec196f
Branches
Tags
1 merge request!1Issue #3263061: [PP-1] Code style cleanup, Schema check, Basic Tests
......@@ -2,25 +2,25 @@
* @file
* Styles for the anchor preview in editors, for example ckeditor.
*/
[data-embed-button="famb_anchor"]{
[data-embed-button="famb_anchor"] {
border: 2px dotted currentColor;
padding: .5rem 1rem;
display:flex !important;
justify-content:center !important;
line-height:1.1;
display: flex !important;
justify-content: center !important;
line-height: 1.1;
}
[data-embed-button="famb_anchor"] .foundation-magellan-anchor{
display:flex;
align-items:center;
[data-embed-button="famb_anchor"] .foundation-magellan-anchor {
display: flex;
align-items: center;
}
[data-embed-button="famb_anchor"] .foundation-magellan-anchor::before{
content:"";
[data-embed-button="famb_anchor"] .foundation-magellan-anchor::before {
content: "";
background-image: url("data:image/svg+xml,%3C!-- Generated by IcoMoon.io --%3E%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' width='512' height='512' viewBox='0 0 512 512'%3E%3Ctitle%3E%3C/title%3E%3Cg id='icomoon-ignore'%3E%3C/g%3E%3Cpath d='M448 288v66.098c-40.261 41.123-96.519 80.825-160 91.254v-189.352h96v-32l-96-37.471c37.282-13.18 64-48.731 64-90.529 0-53.020-42.98-96-96-96-53.021 0-96 42.98-96 96 0 41.798 26.715 77.35 64 90.529v0.006l-96 37.465v32h96v189.352c-63.484-10.429-119.742-50.131-160-91.254v-66.098h-64v32c0 64 128 192 256 192s256-128 256-192v-32h-64zM288 96c0 17.673-14.327 32-32 32s-32-14.327-32-32 14.327-32 32-32c17.673 0 32 14.327 32 32z'%3E%3C/path%3E%3C/svg%3E%0A");
background-repeat:no-repeat;
background-size:contain;
width:1em;
height:1em;
margin-right:.5em;
background-repeat: no-repeat;
background-size: contain;
width: 1em;
height: 1em;
margin-right: .5em;
}
[data-embed-button="famb_anchor"] .foundation-magellan-anchor::after {
content: attr(data-anchor-menu-title) " (#"attr(data-magellan-target)")";
......
......@@ -2,14 +2,14 @@
/**
* @file
* foundation_anchor_menu_block module file.
* Foundation_anchor_menu_block module file.
*/
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Template\Attribute;
/**
* Implements hook_entity_bundle_field_info_alter.
* Implements hook_entity_bundle_field_info_alter().
*/
function foundation_anchor_menu_block_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle) {
if ($entity_type->id() == 'block_content' && $bundle == 'famb_anchor' && !empty($fields['field_block_famb_anchor_id'])) {
......@@ -25,8 +25,7 @@ function foundation_anchor_menu_block_entity_bundle_field_info_alter(&$fields, E
/**
* Implements hook_theme().
*/
function foundation_anchor_menu_block_theme($existing, $type, $theme, $path)
{
function foundation_anchor_menu_block_theme($existing, $type, $theme, $path) {
return [
'famb_anchor_menu' => [
'template' => 'famb-anchor-menu',
......@@ -47,11 +46,11 @@ function foundation_anchor_menu_block_theme($existing, $type, $theme, $path)
],
'block__famb_anchor' => [
'template' => 'block--famb-anchor',
'base hook' => 'block'
'base hook' => 'block',
],
'entity_embed_container__embed_button_famb_anchor' => [
'template' => 'entity-embed-container--embed-button-famb-anchor',
'base hook' => 'entity_embed_container'
'base hook' => 'entity_embed_container',
],
];
}
......@@ -60,7 +59,7 @@ function foundation_anchor_menu_block_theme($existing, $type, $theme, $path)
* Implements hook_theme_suggestions_HOOK_alter().
*/
function foundation_anchor_menu_block_theme_suggestions_block_alter(array &$suggestions, array $variables) {
if(!empty($variables['elements']['content']['#block_content']) && $variables['elements']['content']['#block_content']->bundle() == 'famb_anchor'){
if (!empty($variables['elements']['content']['#block_content']) && $variables['elements']['content']['#block_content']->bundle() == 'famb_anchor') {
$suggestions[] = 'block__famb_anchor';
}
}
......@@ -69,13 +68,13 @@ function foundation_anchor_menu_block_theme_suggestions_block_alter(array &$sugg
* Implements hook_theme_suggestions_HOOK_alter().
*/
function foundation_anchor_menu_block_theme_suggestions_entity_embed_container_alter(array &$suggestions, array $variables) {
if(!empty($variables['element']['#context']) && $variables['element']['#context']['data-embed-button'] == 'famb_anchor'){
if (!empty($variables['element']['#context']) && $variables['element']['#context']['data-embed-button'] == 'famb_anchor') {
$suggestions[] = 'entity_embed_container__embed_button_famb_anchor';
}
}
/**
* Implements HOOK_ckeditor_css_alter().
* Implements hook_ckeditor_css_alter().
*/
function foundation_anchor_menu_block_ckeditor_css_alter(&$css, $editor) {
// Add specific css for ckeditor preview display of anchors:
......
......@@ -45,8 +45,8 @@ class FoundationAnchorMenuBlock extends BlockBase implements BlockPluginInterfac
'updateHistory' => $this->configuration['updateHistory'],
'offsetTopBarSelector' => $this->configuration['offsetTopBarSelector'],
'offset' => $this->configuration['offset'],
]
]
],
],
],
];
}
......@@ -63,8 +63,8 @@ class FoundationAnchorMenuBlock extends BlockBase implements BlockPluginInterfac
'animationEasing' => 'linear',
'threshold' => 50,
'activeClass' => 'is-active',
'deeplinking' => false,
'updateHistory' => false,
'deeplinking' => FALSE,
'updateHistory' => FALSE,
'offsetTopBarSelector' => '.top-bar:first',
'offset' => 0,
];
......@@ -80,102 +80,102 @@ class FoundationAnchorMenuBlock extends BlockBase implements BlockPluginInterfac
$config = $this->getConfiguration();
$form['menu_orientation'] = [
'#type' => 'select',
'#title' => t('Menu orientation'),
'#title' => $this->t('Menu orientation'),
'#options' => [
'vertical' => $this->t('Vertical'),
'horizontal' => $this->t('Horizontal'),
],
'#required' => TRUE,
'#default_value' => isset($config['menu_orientation']) ? $config['menu_orientation'] : 'horizontal',
'#default_value' => $config['menu_orientation'] ?? 'horizontal',
'#description' => $this->t('See <a href="@foundation_docs_vertical_menu_href" target="_blank">Foundation Docs: Vertical Menu</a>', ['@foundation_docs_vertical_menu_href' => 'https://get.foundation/sites/docs/menu.html#vertical-menu']),
];
$form['menu_horizontal_breakpoint'] = [
'#type' => 'select',
'#title' => t('Menu horizontal breakpoint'),
'#title' => $this->t('Menu horizontal breakpoint'),
'#options' => [
'small' => $this->t('Small'),
'medium' => $this->t('Medium') . ' (' . $this->t('Default') . ')',
'large' => $this->t('Large'),
],
'#required' => TRUE,
'#default_value' => isset($config['menu_horizontal_breakpoint']) ? $config['menu_horizontal_breakpoint'] : 'medium',
'#default_value' => $config['menu_horizontal_breakpoint'] ?? 'medium',
'#description' => $this->t('If the screen is smaller than this breakpoint, switches a horizontal menu to vertical.'),
];
$form['list_classes_additional'] = [
'#type' => 'textfield',
'#title' => t('Additional list classes'),
'#title' => $this->t('Additional list classes'),
'#required' => FALSE,
'#default_value' => isset($config['list_classes_additional']) ? $config['list_classes_additional'] : '',
'#default_value' => $config['list_classes_additional'] ?? '',
'#description' => $this->t('Adds further custom classes to the list (&lt;ul&gt;) element. Separated by space.'),
];
// Magellan settings:
// TODO - Put in a field group.
// @todo Put in a field group.
$form['animationDuration'] = [
'#title' => t('Animation Duration'),
'#title' => $this->t('Animation Duration'),
'#type' => 'number',
'#step' => 1,
'#min' => 0,
'#size' => 5,
'#required' => TRUE,
'#default_value' => isset($config['animationDuration']) ? $config['animationDuration'] : 500,
'#default_value' => $config['animationDuration'] ?? 500,
'#description' => $this->t('Amount of time, in ms, the animated scrolling should take between locations. Default: 500'),
];
$form['animationEasing'] = [
'#title' => t('Animation Easing'),
'#title' => $this->t('Animation Easing'),
'#type' => 'select',
'#options' => [
'linear' => $this->t('Linear'),
'swing' => $this->t('Swing'),
],
'#required' => TRUE,
'#default_value' => isset($config['animationEasing']) ? $config['animationEasing'] : 'linear',
'#default_value' => $config['animationEasing'] ?? 'linear',
'#description' => $this->t('Animation style to use when scrolling between locations. Can be `swing` or `linear`. Default: linear'),
];
$form['threshold'] = [
'#title' => t('Threshold'),
'#title' => $this->t('Threshold'),
'#type' => 'number',
'#step' => 1,
'#min' => 0,
'#size' => 5,
'#required' => TRUE,
'#default_value' => isset($config['threshold']) ? $config['threshold'] : 50,
'#default_value' => $config['threshold'] ?? 50,
'#description' => $this->t('Number of pixels to use as a marker for location changes. Default: 50'),
];
$form['activeClass'] = [
'#type' => 'textfield',
'#title' => t('Active Class'),
'#title' => $this->t('Active Class'),
'#required' => TRUE,
'#default_value' => isset($config['activeClass']) ? $config['activeClass'] : 'is-active',
'#default_value' => $config['activeClass'] ?? 'is-active',
'#description' => $this->t('Class applied to the active locations link on the magellan container. Default: is-active'),
];
$form['deeplinking'] = [
'#type' => 'checkbox',
'#title' => t('Deeplinking'),
'#title' => $this->t('Deeplinking'),
'#required' => FALSE,
'#default_value' => isset($config['deeplinking']) ? $config['deeplinking'] : FALSE,
'#default_value' => $config['deeplinking'] ?? FALSE,
'#description' => $this->t('Allows the script to manipulate the url of the current page, and if supported, alter the history. Default: FALSE'),
];
$form['updateHistory'] = [
'#type' => 'checkbox',
'#title' => t('Update History'),
'#title' => $this->t('Update History'),
'#required' => FALSE,
'#default_value' => isset($config['updateHistory']) ? $config['updateHistory'] : FALSE,
'#default_value' => $config['updateHistory'] ?? FALSE,
'#description' => $this->t('Update the browser history with the active link, if deep linking is enabled. Default: FALSE'),
];
$form['offsetTopBarSelector'] = [
'#type' => 'textfield',
'#title' => t('Offset (Topbar) Selector'),
'#title' => $this->t('Offset (Topbar) Selector'),
'#required' => FALSE,
'#default_value' => isset($config['offsetTopBarSelector']) ? $config['offsetTopBarSelector'] : '.top-bar:first',
'#default_value' => $config['offsetTopBarSelector'] ?? '.top-bar:first',
'#description' => $this->t('jQuery Top bar selector. If given used to calculate the offset automatically. Leave emtpy to only use a manual offset value. Default: .top-bar:first'),
];
$form['offset'] = [
'#type' => 'number',
'#step' => 1,
'#title' => t('Offset (additional)'),
'#title' => $this->t('Offset (additional)'),
'#required' => FALSE,
'#default_value' => isset($config['offset']) ? $config['offset'] : 0,
'#default_value' => $config['offset'] ?? 0,
'#description' => $this->t('Number of pixels to offset the scroll of the page on item click if using a sticky nav bar. Summed up with offsetTopBarSelector.outerHeight().'),
];
......@@ -207,7 +207,10 @@ class FoundationAnchorMenuBlock extends BlockBase implements BlockPluginInterfac
public function blockValidate($form, FormStateInterface $form_state) {
$menu_orientation = $form_state->getValue('menu_orientation');
if (!in_array($menu_orientation, ['vertical', 'horizontal'])) {
$form_state->setErrorByName('menu_orientation', $this->t('Must be @vertical or @horizontal', ['@vertical' => $this->t('Vertical'), '@horizontal' => $this->t('Horizontal')]));
$form_state->setErrorByName('menu_orientation', $this->t('Must be @vertical or @horizontal', [
'@vertical' => $this->t('Vertical'),
'@horizontal' => $this->t('Horizontal'),
]));
}
$menu_horizontal_breakpoint = $form_state->getValue('menu_horizontal_breakpoint');
if (!in_array($menu_horizontal_breakpoint, ['small', 'medium', 'large'])) {
......
<?php
namespace Drupal\Tests\foundation_anchor_menu_block\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* This class provides methods for testing foundation_anchor_menu_block.
*
* @group foundation_anchor_menu_block
*/
class FoundationANchorMenuBlockFunctionalTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'foundation_sites',
'block_content',
'embed',
'entity_embed',
'entity_browser',
'test_page_test',
'foundation_anchor_menu_block',
];
/**
* A user with authenticated permissions.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $user;
/**
* A user with admin permissions.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->config('system.site')->set('page.front', '/test-page')->save();
$this->user = $this->drupalCreateUser([]);
$this->adminUser = $this->drupalCreateUser([]);
$this->adminUser->addRole($this->createAdminRole('admin', 'admin'));
$this->adminUser->save();
$this->drupalLogin($this->adminUser);
}
/**
* Tests if the module installation, won't break the site.
*/
public function testInstallation() {
$session = $this->assertSession();
$this->drupalGet('<front>');
$session->statusCodeEquals(200);
}
/**
* My test.
*/
public function testSomething() {
$session = $this->assertSession();
$page = $this->getSession()->getPage();
// See if it is possible to set a block in the header:
$this->drupalGet('/admin/structure/block/add/foundation_anchor_menu_block_block/bartik?region=header');
$session->statusCodeEquals(200);
$page->pressButton('edit-actions-submit');
$session->statusCodeEquals(200);
$session->pageTextContains('The block configuration has been saved.');
$this->drupalGet('<front>');
$session->elementExists('css', '#block-foundationanchormenublockdynamicbyjavascript');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment