Skip to content
Snippets Groups Projects
Commit 891dcf16 authored by Liam Morland's avatar Liam Morland
Browse files

Coding standards

parent fa25756c
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,7 @@ class GessoHelperCommands extends DrushCommands implements SiteAliasManagerAware
* @command gesso
* @throws \Exception
*/
public function gesso($name, array $options = ['description' => null, 'machine-name' => null]) {
public function gesso($name, array $options = ['description' => NULL, 'machine-name' => NULL]) {
// Get new theme options.
if (!isset($name)) {
$name = $options['name'];
......@@ -67,7 +67,7 @@ class GessoHelperCommands extends DrushCommands implements SiteAliasManagerAware
// Get theme paths.
$drupalRoot = Drush::bootstrapManager()->getRoot();
$gesso_path = Path::join($drupalRoot, drupal_get_path('theme', 'gesso'));
$theme_path = substr($gesso_path, 0, strrpos( $gesso_path, '/'));
$theme_path = substr($gesso_path, 0, strrpos($gesso_path, '/'));
$new_path = Path::join($theme_path, $machine_name);
// Copy the Gesso theme directory recursively to the new theme’s location.
......@@ -140,7 +140,7 @@ class GessoHelperCommands extends DrushCommands implements SiteAliasManagerAware
$this->io()->note(dt('The gulp commands for !name are still gessoBuild and gessoWatch. If you want to change '
. 'those, you will need to modify the gulpfile and any build processes and/or CI tools.', [
'!name' => $name,
]));
]));
}
/**
......@@ -186,7 +186,7 @@ class GessoHelperCommands extends DrushCommands implements SiteAliasManagerAware
* before finally deleting the directory itself.
*
* @param string $path
* Path to the top-level directory
* Path to the top-level directory.
*/
private function gesso_recursive_rm($path) {
if (is_dir($path)) {
......@@ -196,7 +196,8 @@ class GessoHelperCommands extends DrushCommands implements SiteAliasManagerAware
$subpath = Path::join($path, $item);
if (is_dir($subpath)) {
$this->gesso_recursive_rm($subpath);
} else {
}
else {
drush_op('unlink', $subpath);
}
}
......@@ -204,4 +205,5 @@ class GessoHelperCommands extends DrushCommands implements SiteAliasManagerAware
drush_op('rmdir', $path);
}
}
}
<?php
namespace Drupal\gesso_helper\TwigExtension;
/**
* Load custom twig functions from Pattern Lab
* Load custom twig functions from Pattern Lab.
*/
class GessoExtensionAdapter extends \Twig_Extension {
/**
*
*/
public function __construct() {
GessoExtensionLoader::init();
}
/**
*
*/
public function getFunctions() {
return GessoExtensionLoader::get();
}
......
......@@ -3,23 +3,32 @@
namespace Drupal\gesso_helper\TwigExtension;
/**
* Load custom twig functions from Pattern Lab
* Load custom twig functions from Pattern Lab.
*/
class GessoExtensionLoader {
static $objects = [];
static public function init() {
/**
*
*/
public static function init() {
if (!self::$objects) {
static::loadAll();
}
}
static public function get() {
/**
*
*/
public static function get() {
return !empty(self::$objects) ? self::$objects : [];
}
static protected function loadAll() {
/**
*
*/
protected static function loadAll() {
$theme = \Drupal::config('system.theme')->get('default');
$themeLocation = drupal_get_path('theme', $theme);
$themePath = DRUPAL_ROOT . '/' . $themeLocation . '/';
......@@ -27,7 +36,10 @@ class GessoExtensionLoader {
static::load($fullPath . 'add_attributes.function.drupal.php');
}
static protected function load($file) {
/**
*
*/
protected static function load($file) {
include $file;
self::$objects[] = $function;
}
......
......@@ -5,7 +5,7 @@
* Provides the necessary hooks for the block theme suggestions.
*/
use \Drupal\block_content\BlockContentInterface;
use Drupal\block_content\BlockContentInterface;
/**
* Implements hook_theme_suggestions_HOOK_alter().
......
......@@ -5,6 +5,9 @@
* Field template functions.
*/
/**
*
*/
function gesso_theme_suggestions_field_alter(&$suggestions, $variables) {
$suggestions[] = 'field__node__' . $variables['element']['#field_name'] . '__' . $variables['element']['#bundle'] . '__' . $variables['element']['#view_mode'];
$suggestions[] = 'field__node__' . $variables['element']['#field_name'] . '__' . $variables['element']['#bundle'] . '__' . $variables['element']['#view_mode'];
}
......@@ -27,4 +27,4 @@ function gesso_preprocess_fieldset(&$vars) {
function gesso_theme_suggestions_form_alter(array &$suggestions, array $variables) {
$form_id = $variables['element']['#form_id'];
$suggestions[] = 'form__' . $form_id;
}
\ No newline at end of file
}
<?php
/**
* @file
*/
/**
* Implements theme_preprocess_menu_local_tasks()
*
* @param $variables
*/
function gesso_preprocess_menu_local_tasks(&$variables) {
foreach (['primary', 'secondary'] as $type) {
$tabs = [];
// Sort the tabs by #weight.
uasort($variables[$type], ['Drupal\Component\Utility\SortArray', 'sortByWeightProperty']);
foreach (array_keys($variables[$type]) as $key) {
// Add the tab to a new array.
$tabs[$key] = [
'active' => $variables[$type][$key]['#active'],
'url' => $variables[$type][$key]['#link']['url']->toString(),
'text' => \Drupal\Component\Utility\Html::escape($variables[$type][$key]['#link']['title'])
];
// Check if the tab should be shown by rendering the original.
$link = \Drupal::service('renderer')->render($variables[$type][$key]);
if (!$link) {
unset($tabs[$key]);
}
}
// Overwrite the original tabs data.
$variables[$type] = $tabs;
}
}
use Drupal\Component\Utility\Html;
/**
*
*/
function gesso_preprocess_menu_local_tasks(&$variables) {
foreach (['primary', 'secondary'] as $type) {
$tabs = [];
// Sort the tabs by #weight.
uasort($variables[$type], ['Drupal\Component\Utility\SortArray', 'sortByWeightProperty']);
foreach (array_keys($variables[$type]) as $key) {
// Add the tab to a new array.
$tabs[$key] = [
'active' => $variables[$type][$key]['#active'],
'url' => $variables[$type][$key]['#link']['url']->toString(),
'text' => Html::escape($variables[$type][$key]['#link']['title']),
];
// Check if the tab should be shown by rendering the original.
$link = \Drupal::service('renderer')->render($variables[$type][$key]);
if (!$link) {
unset($tabs[$key]);
}
}
// Overwrite the original tabs data.
$variables[$type] = $tabs;
}
}
<?php
/**
* @file
*/
/**
* Implements theme_suggestions_taxonomy_term_alter()
*
......
<?php
/**
* Implements views_theme_suggestions_views_view().
* @file
*/
/**
* Implements hook_theme_suggestions_views_view().
*/
function views_theme_suggestions_views_view(array $variables) {
$suggestions = [];
......@@ -15,7 +19,7 @@ function views_theme_suggestions_views_view(array $variables) {
}
/**
* Implements views_theme_suggestions_views_view_unformatted().
* Implements hook_theme_suggestions_views_view_unformatted().
*/
function views_theme_suggestions_views_view_unformatted(array $variables) {
$suggestions = [];
......@@ -36,8 +40,8 @@ function gesso_preprocess_views_view(&$variables) {
}
/**
* Implements hook_theme_suggestions_container_alter().
*/
* Implements hook_theme_suggestions_container_alter().
*/
function gesso_theme_suggestions_container_alter(array &$suggestions, array $variables) {
// A list of view names in which to exclude the container markup.
// Included views will use container--no-wrapper.html.twig instead of container.html.twig.
......
......@@ -5,9 +5,9 @@
* Theme file for uw_fdsu_theme_resp.
*/
use Drupal\taxonomy\Entity\Term;
use Drupal\Core\Datetime;
use Drupal\Core\DateTimeZone;
use Drupal\file\Plugin\Field\FieldType\FileFieldItemList;
use Drupal\image\Plugin\Field\FieldType\ImageItem;
use Drupal\Core\Form\FormStateInterface;
/**
* @file
......@@ -42,11 +42,11 @@ function uw_fdsu_theme_resp_preprocess_responsive_image(&$variables) {
foreach ($variables['sources'] as $source) {
// Set the a variable with the actual source info that we need.
$new_sources[] = array(
$new_sources[] = [
'srcset' => $source['srcset']->value(),
'media' => $source['media']->value(),
'type' => $source['type']->value(),
);
];
}
// Set the sources variable to the new sources.
......@@ -82,7 +82,7 @@ function uw_fdsu_theme_resp_preprocess_region(&$variables) {
*
* Add settings for colour scheme.
*/
function uw_fdsu_theme_resp_form_system_theme_settings_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id = NULL) {
function uw_fdsu_theme_resp_form_system_theme_settings_alter(&$form, FormStateInterface &$form_state, $form_id = NULL) {
// Work-around for a core bug affecting admin themes. See issue #943212.
if (isset($form_id)) {
......@@ -90,14 +90,14 @@ function uw_fdsu_theme_resp_form_system_theme_settings_alter(&$form, \Drupal\Cor
}
// Fieldset for colour scheme.
$form['colour_scheme'] = array(
$form['colour_scheme'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => t('Colour scheme'),
);
];
// Colour scheme select list.
$form['colour_scheme']['wcms_colour_scheme'] = array(
$form['colour_scheme']['wcms_colour_scheme'] = [
'#type' => 'select',
'#default_value' => theme_get_setting('wcms_colour_scheme', 'uw_fdsu_theme_resp') ? theme_get_setting('wcms_colour_scheme', 'uw_fdsu_theme_resp') : 'default',
'#description' => t("Select a color scheme to use"),
......@@ -111,7 +111,7 @@ function uw_fdsu_theme_resp_form_system_theme_settings_alter(&$form, \Drupal\Cor
'org-sci' => 'Science (blue)',
'org-school' => 'School (red)',
],
);
];
}
/**
......@@ -148,7 +148,7 @@ function _uw_fdsu_theme_resp_get_field_value_from_paragraph($paragraph, $field)
* - sources: An array of image sources.
* - alt: The alternative text.
*/
function _uw_fdsu_theme_resp_add_responsive_image_variables(array &$variables, Drupal\image\Plugin\Field\FieldType\ImageItem $field, string $responsive_image_style) : ?array {
function _uw_fdsu_theme_resp_add_responsive_image_variables(array &$variables, ImageItem $field, string $responsive_image_style) : ?array {
// If there is a file present, set responsive image variables.
if ($file = $field->entity) {
......@@ -192,7 +192,7 @@ function _uw_fdsu_theme_resp_add_responsive_image_variables(array &$variables, D
* An array of image properties or NULL if $field does not contain the
* required information.
*/
function _uw_fdsu_theme_resp_get_image_info(Drupal\file\Plugin\Field\FieldType\FileFieldItemList $field) {
function _uw_fdsu_theme_resp_get_image_info(FileFieldItemList $field) {
// If there is an image, process it.
if ($img_entity = $field->first()) {
......
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