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

Coding standards

parent d8cecfe1
No related branches found
No related tags found
No related merge requests found
......@@ -3,11 +3,10 @@
namespace Drupal\uw_cfg_common\Service;
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
/**
* Class UWService
* Class UWService.
*
* @package Drupal\uw_cfg_common\Service
*/
......@@ -46,14 +45,16 @@ class UWService implements UWServiceInterface {
}
/**
* {@inheritDoc}
*/
* {@inheritDoc}
*/
public function getTeaserContent(NodeInterface $node, array $variables_to_get, string $teaser_type): array {
// Step through each of the variables to get and set the variables for the teaser content.
// Step through each of the variables to get and set the variables for the
// teaser content.
foreach ($variables_to_get as $variable_to_get) {
// Switch on the variable to get and set the variables for the teaser content.
// Switch on the variable to get and set the variables for the teaser
// content.
switch ($variable_to_get) {
case 'title':
......@@ -74,8 +75,9 @@ class UWService implements UWServiceInterface {
// field_uw_<content_type>_date.
$field_name = 'field_uw_' . trim($teaser_type) . '_date';
// Set the date variable, once returned to the calling function, they can
// change the date format as required (i.e. change it to long-date or date-time).
// Set the date variable, once returned to the calling function, they
// can change the date format as required (i.e. change it to long-date
// or date-time).
$variables['date'] = $node->$field_name->getString();
break;
......@@ -104,7 +106,8 @@ class UWService implements UWServiceInterface {
// Ensure that we have an image before adding variables.
if ($image !== NULL) {
// Get all the image variables, including the sources using the prepareResponsiveImage function.
// Get all the image variables, including the sources using the
// prepareResponsiveImage function.
$image_variables = $this->prepareResponsiveImage($image, 'uw_ris_media');
// Set the responsive image variables for the teaser content.
......@@ -116,7 +119,8 @@ class UWService implements UWServiceInterface {
case 'tags':
// Set the field name for the tags which is field_uw_<content_type>_tags'.
// Set the field name for the tags which is
// field_uw_<content_type>_tags.
$field_name = 'field_uw_' . trim($teaser_type) . '_tags';
// Get all the taxonomy terms for the blog.
......@@ -133,12 +137,13 @@ class UWService implements UWServiceInterface {
case 'content':
// Set the field name for the summary, which is field_name<content_type>_summary.
// Set the field name for the summary, which is
// field_name<content_type>_summary.
$field_name = 'field_uw_' . $teaser_type . '_summary';
// Set the render array for the summary, we simply can not just send the
// value as Drupal will just render it with no filters or HTML applied.
// We need to send the full render array.
// Set the render array for the summary, we simply can not just send
// the value as Drupal will just render it with no filters or HTML
// applied. We need to send the full render array.
$variables['content'] = [
'#type' => 'processed_text',
'#text' => $node->$field_name->value,
......
......@@ -4,6 +4,9 @@ namespace Drupal\uw_cfg_common\Service;
use Drupal\Core\Entity\EntityInterface;
/**
* Interface for UW services.
*/
interface UWServiceInterface {
/**
......@@ -15,7 +18,8 @@ interface UWServiceInterface {
* Image style to be used for responsive image.
*
* @return array
* Array with details for responsive image.
* Array with details for responsive image.
*/
public function prepareResponsiveImage(EntityInterface $entity, string $image_style): array;
}
......@@ -152,9 +152,10 @@ function uw_cfg_common_toolbar_alter(&$items) {
// Get the roles of the user.
$roles = $current_user->getRoles();
// If there is only 1 role and that first role is authenticated, remove the manage link.
// If there are multiple roles then we know that they will have the Manage link, we are
// only removing the manage link for strictly authenticated users only.
// If there is only 1 role and that first role is authenticated, remove the
// manage link. If there are multiple roles then we know that they will have
// the Manage link, we are only removing the manage link for strictly
// authenticated users only.
if (count($roles) == 1 && $roles[0] == 'authenticated') {
// Remove the manage link.
......
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