From 716fe54da13abcc40eb89fb3d52e842e9959698e Mon Sep 17 00:00:00 2001 From: Anthony Klose Date: Wed, 3 Feb 2021 15:22:42 -0600 Subject: [PATCH 1/3] Update AluminumCopyrightBlock.php Set the maxlength to 256 instead of the default 128 --- .../aluminum_blocks/src/Plugin/Block/AluminumCopyrightBlock.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/aluminum_blocks/src/Plugin/Block/AluminumCopyrightBlock.php b/modules/aluminum_blocks/src/Plugin/Block/AluminumCopyrightBlock.php index dbd6234..69cfc9c 100644 --- a/modules/aluminum_blocks/src/Plugin/Block/AluminumCopyrightBlock.php +++ b/modules/aluminum_blocks/src/Plugin/Block/AluminumCopyrightBlock.php @@ -25,6 +25,7 @@ public function getOptions() { 'copyright_text' => [ '#type' => 'textfield', '#title' => $this->t('Copyright text'), + '#maxlength' => 256, '#description' => $this->t('The text to display. You may use tokens such as [site:name] and [date:custom:Y].'), '#default_value' => 'Copyright [date:custom:Y] [site:name]. All rights reserved.', ], From 0ef53779a91a00edadcecfd7905bfbb633251484 Mon Sep 17 00:00:00 2001 From: Scott Sawyer Date: Tue, 16 Apr 2024 11:38:40 -0400 Subject: [PATCH 2/3] Fixes core compatibility requirements, and addresses most if not all coding standards issues. --- README.txt | 3 +- aluminum.info.yml | 4 +- aluminum.module | 2 +- modules/aluminum_blocks/README.txt | 4 +- .../aluminum_blocks/aluminum_blocks.info.yml | 10 ++-- .../aluminum_blocks/aluminum_blocks.module | 5 +- .../src/Plugin/Block/AluminumBlockBase.php | 53 +++++++++++------- .../Plugin/Block/AluminumCopyrightBlock.php | 54 +++++++++--------- .../src/Plugin/Block/AluminumFollowBlock.php | 35 ++++++++---- .../Plugin/Block/AluminumPhoneNumberBlock.php | 24 ++++---- .../Block/AluminumPhoneNumberListBlock.php | 24 +++++--- .../aluminum_vault/aluminum_vault.info.yml | 6 +- modules/aluminum_vault/aluminum_vault.module | 39 ++++++++++--- .../src/Form/AluminumVaultSettingsForm.php | 11 +--- modules/aluminum_vault/src/VaultConfig.php | 56 +++++++++++-------- src/Aluminum/Exception/AluminumException.php | 12 ++-- src/Aluminum/Traits/IdentifiableTrait.php | 48 ++++++++++++---- src/Aluminum/Traits/InvokableTrait.php | 30 +++++++--- src/Aluminum/Traits/StaticInvokableTrait.php | 30 +++++++--- src/Controller/AluminumAdminController.php | 12 ++-- 20 files changed, 285 insertions(+), 177 deletions(-) diff --git a/README.txt b/README.txt index 4f50fca..f5090fa 100644 --- a/README.txt +++ b/README.txt @@ -1,3 +1,4 @@ ABOUT -This base module is used by all of the other aluminum modules--you only need it enabled if you're using one or more of those. +This base module is used by all of the other aluminum modules--you only need it + enabled if you're using one or more of those. diff --git a/aluminum.info.yml b/aluminum.info.yml index a942756..9a47671 100644 --- a/aluminum.info.yml +++ b/aluminum.info.yml @@ -1,6 +1,6 @@ name: Aluminum Core type: module description: "Provides a pluggable set of building blocks for composing a website." -version: 8.x-1.0-alpha1 -core: 8.x +version: 8.x-1.0-alpha2 +core_version_requirement: ^8.8 || ^9 || ^10 package: Aluminum diff --git a/aluminum.module b/aluminum.module index 06dd7aa..41cb7fc 100644 --- a/aluminum.module +++ b/aluminum.module @@ -2,7 +2,7 @@ /** * @file - * Provides some common configurable blocks for use in the Spacelift theme + * Provides some common configurable blocks for use in the Spacelift theme. */ use Drupal\Core\Routing\RouteMatchInterface; diff --git a/modules/aluminum_blocks/README.txt b/modules/aluminum_blocks/README.txt index f2553bf..d8bcf98 100644 --- a/modules/aluminum_blocks/README.txt +++ b/modules/aluminum_blocks/README.txt @@ -1,7 +1,7 @@ ABOUT -This module simply creates some basic user-configurable blocks that are generally -useful for most sites. +This module simply creates some basic user-configurable blocks that are +generally useful for most sites. DEPENDENCIES o Block (in core) diff --git a/modules/aluminum_blocks/aluminum_blocks.info.yml b/modules/aluminum_blocks/aluminum_blocks.info.yml index 57505e2..3ad4e56 100644 --- a/modules/aluminum_blocks/aluminum_blocks.info.yml +++ b/modules/aluminum_blocks/aluminum_blocks.info.yml @@ -1,10 +1,10 @@ name: Aluminum Blocks type: module description: 'Creates some basic user-configurable blocks that are generally useful for most sites.' -version: 8.x-1.0-alpha1 -core: 8.x +version: 8.x-1.0-alpha2 +core_version_requirement: ^8.8 || ^9 || ^10 package: Aluminum dependencies: - - aluminum - - aluminum_vault - - block + - aluminum:aluminum + - aluminum_vault:aluminum_vault + - block:block diff --git a/modules/aluminum_blocks/aluminum_blocks.module b/modules/aluminum_blocks/aluminum_blocks.module index 35dd437..b7a1c21 100644 --- a/modules/aluminum_blocks/aluminum_blocks.module +++ b/modules/aluminum_blocks/aluminum_blocks.module @@ -2,7 +2,7 @@ /** * @file - * Provides some common configurable blocks for use in the Spacelift theme + * Provides some common configurable blocks for use in the Spacelift theme. */ use Drupal\Core\Routing\RouteMatchInterface; @@ -17,6 +17,9 @@ function aluminum_blocks_help($route_name, RouteMatchInterface $route_match) { } } +/** + * Implements hook_theme(). + */ function aluminum_blocks_theme($existing, $type, $theme, $path) { return [ 'aluminum_follow_list' => [ diff --git a/modules/aluminum_blocks/src/Plugin/Block/AluminumBlockBase.php b/modules/aluminum_blocks/src/Plugin/Block/AluminumBlockBase.php index 446367d..5a0db6e 100644 --- a/modules/aluminum_blocks/src/Plugin/Block/AluminumBlockBase.php +++ b/modules/aluminum_blocks/src/Plugin/Block/AluminumBlockBase.php @@ -1,10 +1,4 @@ aluminum_id)) { - return $this->aluminum_id; + /** + * Get the aluminum id. + * + * @return string + * The aluminum id. + */ + public function getAluminumId(): string { + if (!empty($this->$aluminumId)) { + return $this->$aluminumId; } return strtolower(preg_replace([ '/([a-z\d])([A-Z])/', - '/([^_])([A-Z][a-z])/' + '/([^_])([A-Z][a-z])/', ], '$1_$2', self::class)); } /** * Gets the current value for an option returned by getOptions() * - * @param $option_name + * @param string $option_name + * The option name. * @param bool $replace_tokens + * Whether or not to replace tokens. + * * @return string + * The option value. */ - public function getOptionValue($option_name, $replace_tokens = FALSE) { + public function getOptionValue(string $option_name, bool $replace_tokens = FALSE): string { $config = $this->getConfiguration(); $options = $this->getOptions(); - $default = isset($options[$option_name]['#default_value']) ? $options[$option_name]['#default_value'] : ''; + $default = $options[$option_name]['#default_value'] ?? ''; - $value = isset($config[$option_name]) ? $config[$option_name] : $default; + $value = $config[$option_name] ?? $default; if ($replace_tokens) { $value = \Drupal::token()->replace($value); @@ -74,12 +88,12 @@ public function blockForm($form, FormStateInterface $form_state) { foreach ($this->getOptions() as $option_name => $option) { $option += [ '#type' => 'textfield', - '#title' => $this->t(ucfirst(str_replace('_', ' ', $option_name))), + '#title' => ucfirst(str_replace('_', ' ', $option_name)), ]; - $default = isset($option['#default_value']) ? $option['#default_value'] : ''; + $default = $option['#default_value'] ?? ''; - $option['#default_value'] = isset($config[$option_name]) ? $config[$option_name] : $default; + $option['#default_value'] = $config[$option_name] ?? $default; $form[$option_name] = $option; } @@ -110,4 +124,5 @@ public function defaultConfiguration() { return $values; } + } diff --git a/modules/aluminum_blocks/src/Plugin/Block/AluminumCopyrightBlock.php b/modules/aluminum_blocks/src/Plugin/Block/AluminumCopyrightBlock.php index 69cfc9c..eae886b 100644 --- a/modules/aluminum_blocks/src/Plugin/Block/AluminumCopyrightBlock.php +++ b/modules/aluminum_blocks/src/Plugin/Block/AluminumCopyrightBlock.php @@ -1,15 +1,9 @@ [ - '#type' => 'textfield', - '#title' => $this->t('Copyright text'), - '#maxlength' => 256, - '#description' => $this->t('The text to display. You may use tokens such as [site:name] and [date:custom:Y].'), - '#default_value' => 'Copyright [date:custom:Y] [site:name]. All rights reserved.', - ], - ]; - } - /** - * {@inheritdoc} - */ - public function build() { - return [ - '#markup' => sprintf('

%s

', $this->t($this->getOptionValue('copyright_text', TRUE))), - ]; - } + /** + * {@inheritdoc} + */ + public function getOptions() { + return [ + 'copyright_text' => [ + '#type' => 'textfield', + '#title' => $this->t('Copyright text'), + '#maxlength' => 256, + '#description' => $this->t('The text to display. You may use tokens such as [site:name] and [date:custom:Y].'), + '#default_value' => 'Copyright [date:custom:Y] [site:name]. All rights reserved.', + ], + ]; + } + + /** + * {@inheritdoc} + */ + public function build() { + return [ + '#markup' => sprintf('

%s

', $this->t($this->getOptionValue('copyright_text', TRUE))), + ]; + } + } diff --git a/modules/aluminum_blocks/src/Plugin/Block/AluminumFollowBlock.php b/modules/aluminum_blocks/src/Plugin/Block/AluminumFollowBlock.php index 2d9acd6..69657ab 100644 --- a/modules/aluminum_blocks/src/Plugin/Block/AluminumFollowBlock.php +++ b/modules/aluminum_blocks/src/Plugin/Block/AluminumFollowBlock.php @@ -1,15 +1,9 @@ $name) { $options[$id . '_enabled'] = [ '#type' => 'checkbox', - '#title' => $this->t($name . ' enabled'), - '#description' => $this->t($name . ' will be shown if this box is checked.'), + '#title' => $this->t('%name enabled', ['%name' => $name]), + '#description' => $this->t('%name will be shown if this box is checked.', ['%name' => $name]), '#default_value' => TRUE, ]; $options[$id . '_weight'] = [ '#type' => 'textfield', - '#title' => $this->t($name . ' weight'), - '#description' => $this->t('This integer defines the weight of ' . $name . ' in relation to other links.'), + '#title' => $this->t('%name weight', ['%name' => $name]), + '#description' => $this->t('This integer defines the weight of %name in relation to other links.', ['%name' => $name]), '#default_value' => $weight, ]; @@ -59,6 +54,15 @@ public function getOptions() { return $options; } + /** + * Icon class. + * + * @param string $id + * The id. + * + * @return mixed|string + * The icon class. + */ protected function iconClass($id) { $config = aluminum_vault_config(); @@ -71,6 +75,12 @@ protected function iconClass($id) { return $class; } + /** + * Get social networks. + * + * @return array + * An array of social networks, keyed by id. + */ protected function getSocialNetworks() { $config = aluminum_vault_config(); @@ -84,7 +94,7 @@ protected function getSocialNetworks() { 'name' => $name, 'weight' => $this->getOptionValue($id . '_weight'), 'url' => $config[$id][$id . '_page_url'], - 'icon_class' => $this->iconClass($id) + 'icon_class' => $this->iconClass($id), ]; } } @@ -110,4 +120,5 @@ public function build() { '#link_target' => $this->getOptionValue('link_target', '_blank'), ]; } + } diff --git a/modules/aluminum_blocks/src/Plugin/Block/AluminumPhoneNumberBlock.php b/modules/aluminum_blocks/src/Plugin/Block/AluminumPhoneNumberBlock.php index a0428e9..cf9461a 100644 --- a/modules/aluminum_blocks/src/Plugin/Block/AluminumPhoneNumberBlock.php +++ b/modules/aluminum_blocks/src/Plugin/Block/AluminumPhoneNumberBlock.php @@ -1,17 +1,11 @@ 'aluminum_phone_number', - '#phone_number' => $phone_number, - '#url' => $url, + '#theme' => 'aluminum_phone_number', + '#phone_number' => $phone_number, + '#url' => $url, ]; } + } diff --git a/modules/aluminum_blocks/src/Plugin/Block/AluminumPhoneNumberListBlock.php b/modules/aluminum_blocks/src/Plugin/Block/AluminumPhoneNumberListBlock.php index 7b64101..0efbedf 100644 --- a/modules/aluminum_blocks/src/Plugin/Block/AluminumPhoneNumberListBlock.php +++ b/modules/aluminum_blocks/src/Plugin/Block/AluminumPhoneNumberListBlock.php @@ -1,17 +1,9 @@ getOptionValue('enabled_phone_numbers'))); $phone_numbers = aluminum_vault_phone_numbers(); @@ -85,4 +90,5 @@ public function build() { '#list' => $this->getList(), ]; } + } diff --git a/modules/aluminum_vault/aluminum_vault.info.yml b/modules/aluminum_vault/aluminum_vault.info.yml index e5a0503..6ee5254 100644 --- a/modules/aluminum_vault/aluminum_vault.info.yml +++ b/modules/aluminum_vault/aluminum_vault.info.yml @@ -1,8 +1,8 @@ name: Aluminum Vault type: module description: 'Provides a common configuration interface used by Aluminum' -version: 8.x-1.0-alpha1 -core: 8.x +version: 8.x-1.0-alpha2 +core_version_requirement: ^8.8 || ^9 || ^10 package: Aluminum dependencies: - - aluminum + - aluminum:aluminum diff --git a/modules/aluminum_vault/aluminum_vault.module b/modules/aluminum_vault/aluminum_vault.module index e6407dc..51473c7 100644 --- a/modules/aluminum_vault/aluminum_vault.module +++ b/modules/aluminum_vault/aluminum_vault.module @@ -2,7 +2,7 @@ /** * @file - * Provides a common configuration interface for Aluminum + * Provides a common configuration interface for Aluminum. */ use Drupal\Core\Routing\RouteMatchInterface; @@ -17,6 +17,12 @@ function aluminum_vault_help($route_name, RouteMatchInterface $route_match) { } } +/** + * Aluminum vault social networks. + * + * @return string[] + * An array of social network names. + */ function aluminum_vault_social_networks() { return [ 'facebook' => 'Facebook', @@ -27,6 +33,12 @@ function aluminum_vault_social_networks() { ]; } +/** + * Aluminum vault phone numbers. + * + * @return array[] + * An array of phone numbers. + */ function aluminum_vault_phone_numbers() { return [ 'phone_number_toll_free' => [ @@ -47,7 +59,16 @@ function aluminum_vault_phone_numbers() { ]; } -function aluminum_vault_config($group = null) { +/** + * Aluminum vault config. + * + * @param string|null $group + * The group. + * + * @return array|mixed|null + * An array or something. + */ +function aluminum_vault_config($group = NULL) { $config_name = 'aluminum_vault'; $config = \Drupal::config('aluminum_vault.settings'); @@ -90,7 +111,7 @@ function aluminum_vault_aluminum_vault_groups() { function aluminum_vault_aluminum_vault_config() { $config = []; - // General config + // General config. $config['base_icon_class'] = [ '#type' => 'textfield', '#title' => t('Base icon class'), @@ -98,7 +119,7 @@ function aluminum_vault_aluminum_vault_config() { '#vault_group' => 'general', ]; - // Contact info + // Contact info. foreach (aluminum_vault_phone_numbers() as $id => $info) { $config[$id] = [ '#type' => 'tel', @@ -108,19 +129,19 @@ function aluminum_vault_aluminum_vault_config() { ]; } - // Social network settings + // Social network settings. foreach (aluminum_vault_social_networks() as $id => $name) { $config[$id . '_icon_class'] = [ '#type' => 'textfield', - '#title' => t($name . ' icon class'), - '#description' => t('This icon class will be used to represent ' . $name . '.'), + '#title' => t('%name icon class', ['%name' => $name]), + '#description' => t('This icon class will be used to represent %name.', ['%name' => $name]), '#vault_group' => $id, ]; $config[$id . '_page_url'] = [ '#type' => 'textfield', - '#title' => t($name . ' page URL'), - '#description' => t('The URL used when linking to this site\'s ' . $name . ' page.'), + '#title' => t('%name page URL', ['%name' => $name]), + '#description' => t('The URL used when linking to this site\'s %name page.', ['%name' => $name]), '#vault_group' => $id, ]; } diff --git a/modules/aluminum_vault/src/Form/AluminumVaultSettingsForm.php b/modules/aluminum_vault/src/Form/AluminumVaultSettingsForm.php index 61b70af..f0d12f3 100644 --- a/modules/aluminum_vault/src/Form/AluminumVaultSettingsForm.php +++ b/modules/aluminum_vault/src/Form/AluminumVaultSettingsForm.php @@ -1,22 +1,16 @@ invokeAll('aluminum_vault_groups'); @@ -45,28 +42,37 @@ public function getVaultGroups() { } /** - * Standardizes some defaults for both config options and groups + * Standardizes some defaults for both config options and groups. * - * @param $data + * @param array $data + * The data array. * @param array $defaults + * The defaults. + * * @return mixed + * An array of data items. */ - protected function prepareVaultData($data, $defaults = []) { + protected function prepareVaultData(array $data, array $defaults = []) { foreach ($data as $data_id => $data_array) { $data[$data_id] += $defaults + [ - '#vault_id' => $data_id, - '#title' => $this->getTitleFromId($data_id), - '#weight' => 0, - ]; + '#vault_id' => $data_id, + '#title' => $this->getTitleFromId($data_id), + '#weight' => 0, + ]; } - /*usort($data, function ($a, $b) { - return $a['weight'] - $b['weight']; - });*/ - return $data; } + /** + * Get title from id. + * + * @param string $id + * The id. + * + * @return string + * The title. + */ protected function getTitleFromId($id) { return ucfirst(str_replace('_', ' ', $id)); } @@ -76,14 +82,18 @@ public function getOptionValue($option, FormStateInterface $form_state = null) { if (!is_null($form_state) && $form_state->hasValue($option['#vault_id'])) { $value = $form_state->getValue($option['#vault_id']); - } elseif (isset($config[$option['#vault_id']])) { + } + elseif (isset($config[$option['#vault_id']])) { $value = $config[$option['#vault_id']]; - } elseif (isset($option['#default_value'])) { + } + elseif (isset($option['#default_value'])) { $value = $option['##default_value']; - } else { + } + else { $value = ''; } return $value; } + } diff --git a/src/Aluminum/Exception/AluminumException.php b/src/Aluminum/Exception/AluminumException.php index db606b1..d51c2c8 100644 --- a/src/Aluminum/Exception/AluminumException.php +++ b/src/Aluminum/Exception/AluminumException.php @@ -1,14 +1,10 @@ id)) { throw new AluminumException("No ID set for this object."); @@ -20,20 +25,40 @@ public function getId() { return $this->id; } - public function getName($translate = TRUE) { + /** + * Get name. + * + * @param bool $translate + * Whether to translate name. + * + * @return \Drupal\Core\StringTranslation\TranslatableMarkup|string + * If translated, return the translated name, else, string name. + * + * @throws \Drupal\aluminum\Aluminum\Exception\AluminumException + */ + public function getName(bool $translate = TRUE) { $name = (!empty($this->name)) ? $this->name : $this->generateName(); if ($translate) { if (method_exists($this, 't')) { - $name = $this->t($name); - } else { - $name = t($name); + $name = $this->t('%name', ['%name' => $name]); + } + else { + $name = t('%name', ['%name' => $name]); } } return $name; } + /** + * Generate name. + * + * @return string + * The name. + * + * @throws \Drupal\aluminum\Aluminum\Exception\AluminumException + */ public function generateName() { $id = $this->getId(); @@ -46,4 +71,5 @@ public function generateName() { return $id; } + } diff --git a/src/Aluminum/Traits/InvokableTrait.php b/src/Aluminum/Traits/InvokableTrait.php index ac3995c..9e52e7d 100644 --- a/src/Aluminum/Traits/InvokableTrait.php +++ b/src/Aluminum/Traits/InvokableTrait.php @@ -1,18 +1,31 @@ hookData[$hookName])) { $moduleHandler = \Drupal::moduleHandler(); @@ -32,4 +45,5 @@ protected function invokeHook($hookName, $defaultItem = []) { return $data; } + } diff --git a/src/Aluminum/Traits/StaticInvokableTrait.php b/src/Aluminum/Traits/StaticInvokableTrait.php index a1b4ddd..7809ff0 100644 --- a/src/Aluminum/Traits/StaticInvokableTrait.php +++ b/src/Aluminum/Traits/StaticInvokableTrait.php @@ -1,18 +1,31 @@ Date: Thu, 18 Apr 2024 11:51:14 -0400 Subject: [PATCH 3/3] fixes issue/4 - syntax error --- .../aluminum_blocks/src/Plugin/Block/AluminumBlockBase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/aluminum_blocks/src/Plugin/Block/AluminumBlockBase.php b/modules/aluminum_blocks/src/Plugin/Block/AluminumBlockBase.php index 5a0db6e..b20a5ed 100644 --- a/modules/aluminum_blocks/src/Plugin/Block/AluminumBlockBase.php +++ b/modules/aluminum_blocks/src/Plugin/Block/AluminumBlockBase.php @@ -40,8 +40,8 @@ public function getOptions() { * The aluminum id. */ public function getAluminumId(): string { - if (!empty($this->$aluminumId)) { - return $this->$aluminumId; + if (!empty($this->aluminumId)) { + return $this->aluminumId; } return strtolower(preg_replace([