Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions aluminum.info.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion aluminum.module
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions modules/aluminum_blocks/README.txt
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 5 additions & 5 deletions modules/aluminum_blocks/aluminum_blocks.info.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion modules/aluminum_blocks/aluminum_blocks.module
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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' => [
Expand Down
53 changes: 34 additions & 19 deletions modules/aluminum_blocks/src/Plugin/Block/AluminumBlockBase.php
Original file line number Diff line number Diff line change
@@ -1,60 +1,74 @@
<?php
/**
* Created by PhpStorm.
* User: BMcClure
* Date: 9/9/2016
* Time: 2:44 PM
*/

namespace Drupal\aluminum_blocks\Plugin\Block;

use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Form\FormStateInterface;

/**
* Base class for AluminumBlocks.
*
* Created by PhpStorm.
* User: BMcClure.
* Date: 9/9/2016.
* Time: 2:44 PM.
*/
abstract class AluminumBlockBase extends BlockBase implements BlockPluginInterface {

/**
* Optionally override this to manually set an aluminum_id for this block.
*
* @var string
*/
var $aluminum_id = '';
protected $aluminumId = '';

/**
* Override to specify configuration options
* Override to specify configuration options.
*
* @return array
* An array of options.
*/
public function getOptions() {
return [];
}

public function getAluminumId() {
if (!empty($this->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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -110,4 +124,5 @@ public function defaultConfiguration() {

return $values;
}

}
53 changes: 25 additions & 28 deletions modules/aluminum_blocks/src/Plugin/Block/AluminumCopyrightBlock.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
<?php
/**
* Created by PhpStorm.
* User: BMcClure
* Date: 9/9/2016
* Time: 2:13 PM
*/

namespace Drupal\aluminum_blocks\Plugin\Block;

/**
* Provides a 'Copyright information' block
* Provides a 'Copyright information' block.
*
* @Block(
* id = "aluminum_copyright",
* admin_label = @Translation("Copyright information"),
* )
*/
class AluminumCopyrightBlock extends AluminumBlockBase {
/**
* {@inheritdoc}
*/
public function getOptions() {
return [
'copyright_text' => [
'#type' => 'textfield',
'#title' => $this->t('Copyright text'),
'#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('<p>%s</p>', $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('<p>%s</p>', $this->t($this->getOptionValue('copyright_text', TRUE))),
];
}

}
35 changes: 23 additions & 12 deletions modules/aluminum_blocks/src/Plugin/Block/AluminumFollowBlock.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
<?php
/**
* Created by PhpStorm.
* User: BMcClure
* Date: 9/9/2016
* Time: 2:13 PM
*/

namespace Drupal\aluminum_blocks\Plugin\Block;

/**
* Provides a 'Follow links' block
* Provides a 'Follow links' block.
*
* @Block(
* id = "aluminum_follow",
* admin_label = @Translation("Follow links"),
* )
*/
class AluminumFollowBlock extends AluminumBlockBase {

/**
* {@inheritdoc}
*/
Expand All @@ -41,15 +36,15 @@ public function getOptions() {
foreach (aluminum_vault_social_networks() as $id => $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,
];

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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),
];
}
}
Expand All @@ -110,4 +120,5 @@ public function build() {
'#link_target' => $this->getOptionValue('link_target', '_blank'),
];
}

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<?php
/**
* Created by PhpStorm.
* User: BMcClure
* Date: 9/9/2016
* Time: 2:13 PM
*/

namespace Drupal\aluminum_blocks\Plugin\Block;
use Drupal\Core\Link;

use Drupal\Core\Url;

/**
* Provides a 'Phone number' block
* Provides a 'Phone number' block.
*
* @Block(
* id = "aluminum_phone_number",
* admin_label = @Translation("Phone number"),
* )
*/
class AluminumPhoneNumberBlock extends AluminumBlockBase {

/**
* Get the phone number options.
*
* @return array
* An array of phone number options.
*/
protected function getPhoneNumberOptions() {
$options = [];

Expand Down Expand Up @@ -53,9 +54,10 @@ public function build() {
$url = Url::fromUri('tel:+1 ' . $phone_number);

return [
'#theme' => 'aluminum_phone_number',
'#phone_number' => $phone_number,
'#url' => $url,
'#theme' => 'aluminum_phone_number',
'#phone_number' => $phone_number,
'#url' => $url,
];
}

}
Loading