1,10d0 < From d9ef155aab7d3acbe4430a3973e69b9493b97335 Mon Sep 17 00:00:00 2001 < From: Danny Englander < Date: Fri, 21 Feb 2020 12:57:54 -0800 < Subject: [PATCH] adding updated code for patch < < --- < page_specific_class.module | 7 +++++-- < src/Form/PageSpecificClassSettingsForm.php | 4 +++- < 2 files changed, 8 insertions(+), 3 deletions(-) < 12c2 < index e1c8a47..1730d07 100644 --- > index e32d684..671dcda 100644 15,24c5 < @@ -4,7 +4,7 @@ < * @file < * < * This file adds a class to the body tag page-wise. < - * < + * < */ < use Drupal\Core\Url; < use Drupal\Component\Utility\Html; < @@ -22,6 +22,9 @@ function page_specific_class_preprocess_html(&$variables) { --- > @@ -21,6 +21,7 @@ function page_specific_class_preprocess_html(&$variables) { 28,30c9 < + // Check to see if this is empty. < + if(empty($config->get('url_with_class'))) return; < + --- > + if (!empty($config->get('url_with_class'))) { 33,36c12,18 < foreach ($enteredArr as $key => $values) { < @@ -32,7 +35,7 @@ function page_specific_class_preprocess_html(&$variables) { < $front_page = \Drupal::service('path.matcher')->isFrontPage(); < $enteredPath = \Drupal::service('path.alias_manager')->getPathByAlias($url); --- > foreach ($enteredArr as $values) { > @@ -49,6 +50,7 @@ function page_specific_class_preprocess_html(&$variables) { > } > } > } > + } > } 38,42c20 < - // If current path and entered path by user in page class setting match, < + // If current path and entered path by user in page class setting match, < // then only add respective class. < if ($current_path == $enteredPath) { < foreach ($classes_array as $class) { --- > /** 44c22 < index afaac16..e055383 100644 --- > index 3607156..aab3868 100644 47c25 < @@ -56,8 +56,10 @@ class PageSpecificClassSettingsForm extends ConfigFormBase { --- > @@ -55,8 +55,9 @@ class PageSpecificClassSettingsForm extends ConfigFormBase { 52,56c30,34 < + // Check to see if this is empty. < + if(empty($form_state->getValue('url_with_class'))) return; < $enteredArr = explode(PHP_EOL, $form_state->getValue('url_with_class')); < + < foreach ($enteredArr as $key => $values) { --- > - $enteredArr = explode(PHP_EOL, $form_state->getValue('url_with_class')); > + $url_with_class = $form_state->getValue('url_with_class'); > + if (!empty($url_with_class)) { > + $enteredArr = explode(PHP_EOL, $url_with_class); > foreach ($enteredArr as $values) { 59,61c37,44 < -- < 2.23.0 < --- > @@ -64,6 +65,7 @@ class PageSpecificClassSettingsForm extends ConfigFormBase { > $form_state->setErrorByName('url_with_class', $this->t("@url path needs to start with a slash.", ['@url' => $url])); > } > } > + } > } > > /**