Skip to content
Snippets Groups Projects
Commit 1c506d62 authored by Antonio De Marco's avatar Antonio De Marco
Browse files

Improve code quality #81

parent 4b3936f7
No related branches found
No related tags found
No related merge requests found
......@@ -111,10 +111,8 @@ class Pattern extends RenderElement {
if (self::hasFields($element) && self::hasMultipleSources($element)) {
foreach ($element['#fields'] as $name => $field) {
// This guarantees backward compatibility: single sources be simple.
if (count($field) == 1) {
$element['#fields'][$name] = reset($field);
}
else {
$element['#fields'][$name] = reset($field);
if (count($field) > 1) {
/** @var \Drupal\ui_patterns\Element\PatternContext $context */
$context = $element['#context'];
$context->setProperty('pattern', $element['#id']);
......@@ -180,7 +178,7 @@ class Pattern extends RenderElement {
* TRUE or FALSE.
*/
public static function hasMultipleSources($element) {
return isset($element['#multiple_sources']) && is_bool($element['#multiple_sources']) && $element['#multiple_sources'] == TRUE;
return isset($element['#multiple_sources']) && $element['#multiple_sources'] === TRUE;
}
/**
......@@ -193,7 +191,7 @@ class Pattern extends RenderElement {
* TRUE or FALSE.
*/
public static function hasValidContext($element) {
return isset($element['#context']) && !empty($element['#context']) && is_array($element['#context']) && isset($element['#context']['type']) && !empty($element['#context']['type']);
return isset($element['#context']) && is_array($element['#context']) && !empty($element['#context']['type']);
}
}
......@@ -32,11 +32,11 @@ function ui_patterns_theme() {
*/
function ui_patterns_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
if (UiPatterns::getManager()->isPatternHook($hook) && !empty($variables['context'])) {
if (UiPatterns::getManager()->isPatternHook($hook)) {
\Drupal::moduleHandler()->alter('ui_patterns_suggestions', $suggestions, $variables, $variables['context']);
}
if ($hook == 'patterns_destination' && !empty($variables['context'])) {
if ($hook == 'patterns_destination') {
\Drupal::moduleHandler()->alter('ui_patterns_destination_suggestions', $suggestions, $variables, $variables['context']);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment