localgovdrupal / localgov_campaigns

⛔️ DEPRECATED (Provides campaign sections using page builder paragraph types for LocalGov Drupal.)
GNU General Public License v2.0
0 stars 2 forks source link

Check if colorway styling is present on LGD or needs extra code #33

Closed willguv closed 1 year ago

willguv commented 4 years ago

BLOCKED needs team discussion with @stephen-cox @andybroomfield @Adnan-cds @cjstevens78

The Campaign overview page isn't using the values of the two colorway fields. But it works fine in the Brighton site where classes are added to the "body" field based on the values of the colorway fields. Andy Broomfield has provided us the relevant code. We need to add this to our codebase:

/**
 * Implements hook_preprocess_HOOK().
 */
function bhcc_preprocess_html(&$variables) {
  /** @var \Drupal\bhcc_helper\CurrentPage $current_page */
  $current_page = \Drupal::service('bhcc_helper.current_page');

  // Add content type to body class.
  if ($current_page->isNode() && $current_page->getNode() instanceof \Drupal\node\NodeInterface) {
    $nodeType = $current_page->getNode()->bundle();
    $variables['attributes']['class'][] = 'node';
    $variables['attributes']['class'][] = 'node--' . $nodeType;
    if($nodeType == 'directory_listing') {
      $variables['show_skip_search'] = true;
    }
    if($nodeType == 'campaign_overview') {
      if (!empty($current_page->getNode()) && !empty($current_page->getNode()->field_select_colorway)) {
        $variables['select_colorway'] = $current_page->getNode()->field_select_colorway->value;
      } else {
        $variables['select_colorway'] = 'magenta';
      }
      if (!empty($current_page->getNode()) && !empty($current_page->getNode()->field_select_colourway_accent)) {
        $variables['select_colorway_accent'] = $current_page->getNode()->field_select_colourway_accent->value;
      } else {
        $variables['select_colorway_accent'] = 'magenta';
      }
    }
    if($nodeType == 'html_page') {
      if (!empty($current_page->getNode()) && !empty($current_page->getNode()->field_format)) {
        if ($current_page->getNode()->field_format->value == 'fancy') {
          $variables['html_fancy'] = 'html-fancy';
          if (!empty($current_page->getNode()->field_colourway->value)) {
            $variables['html_colourway'] = $current_page->getNode()->field_colourway->value;
          } else {
            $variables['html_colourway'] = 'pink';
          }
        }
      }
    }
    if($nodeType == 'campaign_page') {
      if (!empty($current_page->getNode()) && !empty($current_page->getNode()->field_campaign)) {
        $parentNID = $current_page->getNode()->field_campaign->first()->getValue()['target_id'];
        $parentNode = \Drupal\node\Entity\Node::load($parentNID);
        if ($parentNode->field_select_colorway) {
          $variables['select_colorway'] = $parentNode->field_select_colorway->value;
        } else {
          $variables['select_colorway'] = 'magenta';
        }
        if ($parentNode->field_select_colourway_accent) {
          $variables['select_colorway_accent'] = $parentNode->field_select_colourway_accent->value;
        } else {
          $variables['select_colorway_accent'] = 'magenta';
        }
      }
    }
  }

}
andybroomfield commented 4 years ago

I thought what we intended to do was for campaigns to implement a way for a theme to declare what colourways it supports and then @Adnan-cds had a technique that added the correct classes into the body class.

Adnan-cds commented 4 years ago

I am linking to the pull request @andybroomfield mentioned above.

willguv commented 4 years ago

@cjstevens78 and @stephen-cox - can you have a chat about this? Thanks

stephen-cox commented 4 years ago

This wasn't implemented in the Campaigns module because there was the idea that the theme could announce the colourway options it supported. The issue (without much detail) is here: https://github.com/localgovdrupal/localgov_campaigns/issues/3

To add the colourways as they stand will be a matter of creating a localgov_campaigns_preprocess_html hook in the Campaigns module and insert the field values into variable that can used in the HTML Twig template. Similar to what Andy did in the code above.

This is more an issue with the Campaigns module, so moving the issue there.

keelanfh commented 1 year ago

Closing as this module is deprecated