cagov / odi-engineering

California Office of Digital Innovation engineering documentation
MIT License
2 stars 0 forks source link

design system adaptation on Generate press theme #66

Closed kkoryaka closed 2 years ago

kkoryaka commented 2 years ago

Our goal is to modify high performant Generate press theme that would be:

WHY:

Progress Outline

Generate Press Child Theme customization:

REMOVE ALL GENERATE PRESS CSS. Add this code to functions.php

add_action( 'wp_print_styles', 'my_deregister_styles', 100 );

function my_deregister_styles() {
    wp_deregister_style( 'generate-style' );
    wp_deregister_style( 'generate-widget-areas' );
}

REMOVE ALL UNNECESSARY GENERATE PRESS JS, AND JS LIBRARIES. Add this code to functions.php

function my_deregister_javascript() {
    wp_deregister_script( 'generate-menu' );
    wp_deregister_script( 'generate-dropdown-click' );
    wp_deregister_script( 'generate-navigation-search' );
    wp_deregister_script( 'generate-back-to-top' );
    wp_deregister_script( 'comment-reply' );
    wp_deregister_script( 'generate-classlist' );
}

/* REMOVE JQUERY */
add_action('wp_enqueue_scripts', 'no_more_jquery');
function no_more_jquery(){
wp_deregister_script('jquery');
}

Load Design System stylesheets. Add this code to functions.php.

function theme_styles()  
{ 

    // Load all of the styles that need to appear on all pages
    wp_enqueue_style( 'main', get_stylesheet_directory_uri(). '/style.css' );
    wp_enqueue_style( 'custom', get_stylesheet_directory_uri(). '/css/ds-cagov.css' );

    // Conditionally load the FlexSlider CSS on the homepage
    if(is_page('home')) {
        wp_enqueue_style('flexslider');
    }

}
add_action('wp_enqueue_scripts', 'theme_styles');

Add Design System CSS CDN import. Create css folder and add `ds-cagov.css' file with following CDN imports:

/* CAGOV COLOR SCHEME */
@import "https://california.azureedge.net/cdt/CAWeb/combined-css/1.0.3/dist/cagov.css";

/* CANNABIS COLOR SCHEME */
/* @import "https://california.azureedge.net/cdt/CAWeb/combined-css/1.0.3/dist/cannabis.css"; */

/* DROUGHT COLOR SCHEME */
/* @import "https://california.azureedge.net/cdt/CAWeb/combined-css/1.0.3/dist/drought.css"; */

Add Design System JS CDN to footer.php. Open footer.php and add this script before </body>:

<!--Adding CAGov Design System JavaScript-->
<script type="module" src='https://california.azureedge.net/cdt/CAWeb/combined-css/1.0.3/dist/index.js'></script>

UPDATE STATEWIDE HEADER. Add following code to functions.php

if ( ! function_exists( 'generate_construct_header' ) ) {
    add_action( 'generate_header', 'generate_construct_header' );
    /**
     * Build the header.
     *
     * @since 1.3.42
     */
    function generate_construct_header() {
        ?>
        <header>
            <div class="header-container">

            <!--skip-to-content-->
            <div id="skip-to-content"><a href="#main-content">Skip to Main Content</a></div>
                <!--end skip-to-content-->

<!--statewide header-->
<div class="official-header">
  <div class="container">
    <div class="official-logo">
        <svg title="ca.gov logo" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px"
            y="0px" width="44px" height="34px" viewBox="0 0 44 34" style="enable-background:new 0 0 44 34;"
            xml:space="preserve">
          <path class="ca" d="M27.4,14c0.1-0.4,0.4-1.5,0.9-3.2c0.1-0.5,0.4-1.3,0.9-2.7c0.5-1.4,0.9-2.5,1.2-3.3c-0.9,0.6-1.8,1.4-2.7,2.3
        c-3.2,3.5-6.9,7.6-8.3,9.8c0.5-0.1,1.5-1.2,4.7-2.3C26.3,14,27.4,14,27.4,14L27.4,14z M26.9,16.2c-10.1,0-14.5,16.1-21.6,16.1
        c-1.6,0-2.8-0.7-3.7-2.1c-0.6-0.9-0.8-2-0.8-3.1c0-2.9,1.4-6.7,4.2-11.1c2.4-3.8,4.9-6.9,7.5-9.2c2.3-2,4.2-3,5.9-3
        c0.9,0,1.6,0.3,2.1,1C20.8,5.2,21,5.8,21,6.5c0,1.3-0.4,2.8-1.3,4.5c-0.8,1.5-1.7,2.8-2.9,3.9c-0.8,0.8-1.4,1.1-1.8,1.1
        c-0.3,0-0.6-0.1-0.8-0.4c-0.2-0.2-0.3-0.4-0.3-0.7c0-0.5,0.4-1,1.2-1.6c1.2-0.9,2.1-1.8,2.8-2.9c1-1.5,1.5-2.8,1.5-3.8
        c0-0.4-0.1-0.7-0.3-0.9c-0.2-0.2-0.5-0.3-0.8-0.3c-0.7,0-1.8,0.5-3.2,1.6c-1.6,1.2-3.2,2.9-5,5C8,14.8,6.3,17.4,5.2,20
        c-1.2,2.7-1.8,5-1.8,6.9c0,0.9,0.3,1.7,0.8,2.3c0.6,0.7,1.3,1.1,2.1,1.1c3.2-0.1,7.2-7.4,8.4-9.1C27,4.3,27.9,4.3,29.8,2.5
        c1.1-1,1.9-1.6,2.5-1.6c0.4,0,0.7,0.1,0.9,0.4c0.2,0.3,0.3,0.5,0.3,0.9c0,0.4-0.2,1-0.6,2c-0.7,1.7-1.3,3.5-1.9,5.4
        c-0.5,1.7-0.9,3-1,3.9c0.2,0,0.4,0,0.5,0c0.4,0,0.7,0,1,0c0.8,0,1.2,0.3,1.2,0.9c0,0.3-0.1,0.5-0.3,0.8c-0.2,0.3-0.4,0.4-0.6,0.5
        c-0.1,0-0.3,0-0.7,0c-0.8,0-1.4,0-1.7,0.1c-0.1,0.4-0.5,4.1-1.1,4.2C26.7,21.5,26.8,16.7,26.9,16.2L26.9,16.2z"/>
          <g>
            <path class="gov" d="M16.8,27.2c0.4,0,0.8,0.2,1.1,0.5c0.3,0.3,0.5,0.7,0.5,1.1c0,0.4-0.2,0.8-0.5,1.1c-0.3,0.3-0.7,0.5-1.1,0.5
            c-0.4,0-0.8-0.2-1.1-0.5c-0.3-0.3-0.5-0.7-0.5-1.1c0-0.4,0.2-0.8,0.5-1.1C16,27.4,16.4,27.2,16.8,27.2L16.8,27.2z"/>
            <path class="gov" d="M26.7,22.9l-1.1,1.1c-0.7-0.8-1.5-1.1-2.5-1.1c-0.8,0-1.5,0.3-2.1,0.8c-0.6,0.6-0.8,1.2-0.8,2
            c0,0.8,0.3,1.5,0.9,2.1c0.6,0.6,1.3,0.8,2.2,0.8c0.6,0,1-0.1,1.4-0.3c0.4-0.2,0.7-0.6,0.9-1.1h-2.4v-1.5h4.2l0,0.4
            c0,0.7-0.2,1.4-0.6,2.1c-0.4,0.7-0.9,1.2-1.5,1.5c-0.6,0.3-1.3,0.5-2.1,0.5c-0.9,0-1.7-0.2-2.3-0.6c-0.7-0.4-1.2-0.9-1.6-1.6
            c-0.4-0.7-0.6-1.5-0.6-2.3c0-1.1,0.4-2.1,1.1-2.9c0.9-1,2-1.5,3.4-1.5c0.7,0,1.4,0.1,2.1,0.4C25.7,22,26.2,22.4,26.7,22.9
            L26.7,22.9z"/>
            <path class="gov" d="M32.2,21.4c1.2,0,2.2,0.4,3.1,1.3c0.9,0.9,1.3,1.9,1.3,3.2c0,1.2-0.4,2.3-1.3,3.1c-0.8,0.9-1.9,1.3-3.1,1.3
            c-1.3,0-2.3-0.4-3.2-1.3c-0.8-0.9-1.3-1.9-1.3-3.1c0-0.8,0.2-1.5,0.6-2.2c0.4-0.7,0.9-1.2,1.6-1.6C30.7,21.5,31.4,21.4,32.2,21.4
            L32.2,21.4z M32.2,22.9c-0.8,0-1.4,0.3-2,0.8c-0.5,0.5-0.8,1.2-0.8,2.1c0,0.9,0.3,1.7,1,2.2c0.5,0.4,1.1,0.6,1.8,0.6
            c0.8,0,1.4-0.3,1.9-0.8c0.5-0.6,0.8-1.2,0.8-2c0-0.8-0.3-1.5-0.8-2C33.6,23.2,33,22.9,32.2,22.9L32.2,22.9z"/>
            <polygon class="gov" points="36.3,21.6 38,21.6 40.1,27.6 42.2,21.6 43.9,21.6 40.8,30 39.3,30 36.3,21.6  "/>
          </g>
        </svg>
      <p class="official-tag"><span class="desktop-only">Official website of the</span> State of California</p>
    </div>
     <?php generate_construct_header_widget();?>
    <cagov-google-translate />
  </div>
    </div>
    <!--end statewide header-->

                <?php
                /**
                 * generate_before_header_content hook.
                 *
                 * @since 0.1
                 */
                do_action( 'generate_before_header_content' );

                if ( ! generate_is_using_flexbox() ) {
                    // Add our main header items.
                    generate_header_items();
                }

                /**
                 * generate_after_header_content hook.
                 *
                 * @since 0.1
                 *
                 * @hooked generate_add_navigation_float_right - 5
                 */
                do_action( 'generate_after_header_content' );
                ?>
            </div>
        </header>
        <?php
    }
}

UPDATE BRANDING. Add following functions to functions.php

if ( ! function_exists( 'generate_construct_site_title' ) ) {
    /**
     * Build the site title and tagline.
     *
     * @since 1.3.28
     */
    function generate_construct_site_title() {
        $generate_settings = wp_parse_args(
            get_option( 'generate_settings', array() ),
            generate_get_defaults()
        );

        // Get the title and tagline.
        $title = get_bloginfo( 'title' );
        $tagline = get_bloginfo( 'description' );

        // If the disable title checkbox is checked, or the title field is empty, return true.
        $disable_title = ( '1' == $generate_settings['hide_title'] || '' == $title ) ? true : false; // phpcs:ignore

        // If the disable tagline checkbox is checked, or the tagline field is empty, return true.
        $disable_tagline = ( '1' == $generate_settings['hide_tagline'] || '' == $tagline ) ? true : false;  // phpcs:ignore

        $schema_type = generate_get_schema_type();

        // Build our site title.
        $site_title = apply_filters(
            'generate_site_title_output',
            sprintf(
                '<span class="main-title org-name-dept">
                    %3$s
                </span>',
                ( is_front_page() && is_home() ) ? 'h1' : 'p',
                esc_url( apply_filters( 'generate_site_title_href', home_url( '/' ) ) ),
                get_bloginfo( 'name' ),
                'microdata' === generate_get_schema_type() ? ' itemprop="headline"' : ''
            )
        );

        // Build our tagline.
        $site_tagline = apply_filters(
            'generate_site_description_output',
            sprintf(
                '<span class="site-description org-name-state"%2$s>
                    %1$s
                </span>',
                html_entity_decode( get_bloginfo( 'description', 'display' ) ), // phpcs:ignore
                'microdata' === generate_get_schema_type() ? ' itemprop="description"' : ''
            )
        );

        // Site title and tagline.
        if ( false === $disable_title || false === $disable_tagline ) {
            if ( generate_needs_site_branding_container() ) {
                echo '<div class="branding site-branding-container"><div class="container with-logo">';
                generate_construct_logo();
            }

            // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- outputting site title and tagline. False positive.
            echo apply_filters(
                'generate_site_branding_output',
                sprintf(
                    '<a class="site-branding grid-org-name" href="/">
                        %1$s
                        %2$s
                    </a>
                    <div class="cagov-nav mobile-icons grid-mobile-icons">
      <div class="cagov-nav mobile-search">
        <button class="search-btn" aria-expanded="true">
          <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="17px"
            height="17px" viewBox="0 0 17 17" style="enable-background:new 0 0 17 17;" xml:space="preserve">
            <path class="blue" d="M16.4,15.2l-4-4c2-2.6,1.8-6.5-0.6-8.9c-1.3-1.3-3-2-4.8-2S3.5,1,2.2,2.3c-2.6,2.6-2.6,6.9,0,9.6
      c1.3,1.3,3,2,4.8,2c1.4,0,2.9-0.5,4.1-1.4l4.1,4c0.2,0.2,0.4,0.3,0.7,0.3c0.2,0,0.5-0.1,0.7-0.3C16.7,16.2,16.7,15.6,16.4,15.2
      L16.4,15.2z M7,12c-1.3,0-2.6-0.5-3.5-1.4c-1.9-1.9-1.9-5.1,0-7C4.4,2.7,5.6,2.1,7,2.1s2.6,0.5,3.5,1.4c0.9,0.9,1.4,2.2,1.4,3.5
      c0,1.3-0.5,2.6-1.4,3.5C9.5,11.5,8.3,12,7,12z"></path>
          </svg>
          <span>Search</span>
        </button>
      </div>
      <button class="menu-trigger cagov-nav open-menu" aria-label="Navigation menu" aria-haspopup="true" aria-expanded="false"
        aria-owns="mainMenu" aria-controls="mainMenu">
        <div class="cagov-nav hamburger">
          <div class="hamburger-box">
            <div class="hamburger-inner"></div>
          </div>
        </div>
        <div class="cagov-nav menu-trigger-label menu-label" data-openlabel="Menu" data-closelabel="Close">Menu</div>
      </button>
    </div>
     <div class="search-container grid-search">
      <form class="site-search" action="/serp/">
        <span class="sr-only" id="SearchInput">Custom Google Search</span>
        <input type="text" id="q" name="q" aria-labelledby="SearchInput" placeholder="Search this website" class="search-textfield">
        <button type="submit" class="search-submit">
          <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
            width="17px" height="17px" viewBox="0 0 17 17" style="enable-background:new 0 0 17 17;"
            xml:space="preserve">
            <path class="blue" d="M16.4,15.2l-4-4c2-2.6,1.8-6.5-0.6-8.9c-1.3-1.3-3-2-4.8-2S3.5,1,2.2,2.3c-2.6,2.6-2.6,6.9,0,9.6
        c1.3,1.3,3,2,4.8,2c1.4,0,2.9-0.5,4.1-1.4l4.1,4c0.2,0.2,0.4,0.3,0.7,0.3c0.2,0,0.5-0.1,0.7-0.3C16.7,16.2,16.7,15.6,16.4,15.2
        L16.4,15.2z M7,12c-1.3,0-2.6-0.5-3.5-1.4c-1.9-1.9-1.9-5.1,0-7C4.4,2.7,5.6,2.1,7,2.1s2.6,0.5,3.5,1.4c0.9,0.9,1.4,2.2,1.4,3.5
        c0,1.3-0.5,2.6-1.4,3.5C9.5,11.5,8.3,12,7,12z" />
          </svg>
          <span class="sr-only">Submit</span>
        </button>
        <button class="search-close">Close</button>
      </form>
    </div>',
                    ( ! $disable_title ) ? $site_title : '',
                    ( ! $disable_tagline ) ? $site_tagline : ''
                )
            );

            if ( generate_needs_site_branding_container() ) {
                echo '</div></div>';
            }
        }
    }
}

if ( ! function_exists( 'generate_construct_logo' ) ) {
    /**
     * Build the logo
     *
     * @since 1.3.28
     */
    function generate_construct_logo() {
        $logo_url = ( function_exists( 'the_custom_logo' ) && get_theme_mod( 'custom_logo' ) ) ? wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), 'full' ) : false;
        $logo_url = ( $logo_url ) ? $logo_url[0] : generate_get_option( 'logo' );

        $logo_url = esc_url( apply_filters( 'generate_logo', $logo_url ) );
        $retina_logo_url = esc_url( apply_filters( 'generate_retina_logo', generate_get_option( 'retina_logo' ) ) );

        // If we don't have a logo, bail.
        if ( empty( $logo_url ) ) {
            return;
        }

        /**
         * generate_before_logo hook.
         *
         * @since 0.1
         */
        do_action( 'generate_before_logo' );

        $attr = apply_filters(
            'generate_logo_attributes',
            array(
                'class' => 'header-image is-logo-image',
                'alt'   => esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
                'src'   => $logo_url,
                'title' => esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
            )
        );

        if ( '' !== $retina_logo_url ) {
            $attr['srcset'] = $logo_url . ' 1x, ' . $retina_logo_url . ' 2x';

            // Add dimensions to image if retina is set. This fixes a container width bug in Firefox.
            if ( function_exists( 'the_custom_logo' ) && get_theme_mod( 'custom_logo' ) ) {
                $data = wp_get_attachment_metadata( get_theme_mod( 'custom_logo' ) );

                if ( ! empty( $data ) ) {
                    $attr['width'] = $data['width'];
                    $attr['height'] = $data['height'];
                }
            }
        } elseif ( generate_is_using_flexbox() ) {
            // Add this to flexbox version only until we can verify it won't conflict with existing installs.
            if ( function_exists( 'the_custom_logo' ) && get_theme_mod( 'custom_logo' ) ) {
                $data = wp_get_attachment_metadata( get_theme_mod( 'custom_logo' ) );

                if ( ! empty( $data ) ) {
                    $attr['width'] = $data['width'];
                    $attr['height'] = $data['height'];
                }
            }
        }

        $attr = array_map( 'esc_attr', $attr );

        $html_attr = '';
        foreach ( $attr as $name => $value ) {
            $html_attr .= " $name=" . '"' . $value . '"';
        }

        // Print our HTML.
        echo apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
            'generate_logo_output',
            sprintf(
                '<a class="site-logo grid-logo" href="%1$s" title="%2$s">
                        <img %3$s />
                </a>',
                esc_url( apply_filters( 'generate_logo_href', home_url( '/' ) ) ),
                esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
                $html_attr
            ),
            $logo_url,
            $html_attr
        );

        /**
         * generate_after_logo hook.
         *
         * @since 0.1
         */
        do_action( 'generate_after_logo' );
    }
}

UPDATE NAVIGATION. Add following functions to functions.php


if ( ! function_exists( 'generate_navigation_position' ) ) {
    /**
     * Build the navigation.
     *
     * @since 0.1
     */
    function generate_navigation_position() {
        /**
         * generate_before_navigation hook.
         *
         * @since 3.0.0
         */
        do_action( 'generate_before_navigation' );
        ?><cagov-navoverlay><div class="container">
            <div class="search-container search-container--small hidden-search">
      <form class="site-search" action="/serp/">
        <span class="sr-only" id="SearchInput2">Custom Google Search</span>
        <input type="text" name="q" aria-labelledby="SearchInput2" placeholder="Search this website"
          class="search-textfield">
        <button type="submit" class="search-submit">
          <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
            width="17px" height="17px" viewBox="0 0 17 17" style="enable-background:new 0 0 17 17;"
            xml:space="preserve">
            <path class="blue" d="M16.4,15.2l-4-4c2-2.6,1.8-6.5-0.6-8.9c-1.3-1.3-3-2-4.8-2S3.5,1,2.2,2.3c-2.6,2.6-2.6,6.9,0,9.6
        c1.3,1.3,3,2,4.8,2c1.4,0,2.9-0.5,4.1-1.4l4.1,4c0.2,0.2,0.4,0.3,0.7,0.3c0.2,0,0.5-0.1,0.7-0.3C16.7,16.2,16.7,15.6,16.4,15.2
        L16.4,15.2z M7,12c-1.3,0-2.6-0.5-3.5-1.4c-1.9-1.9-1.9-5.1,0-7C4.4,2.7,5.6,2.1,7,2.1s2.6,0.5,3.5,1.4c0.9,0.9,1.4,2.2,1.4,3.5
        c0,1.3-0.5,2.6-1.4,3.5C9.5,11.5,8.3,12,7,12z" />
          </svg>
          <span class="sr-only">Submit</span>
        </button>
      </form>
    </div>
        <nav <?php generate_do_attr( 'navigation' ); ?>>
                <?php
                /**
                 * generate_inside_navigation hook.
                 *
                 * @since 0.1
                 *
                 * @hooked generate_navigation_search - 10
                 * @hooked generate_mobile_menu_search_icon - 10
                 */
                do_action( 'generate_inside_navigation' );
                ?>

                <?php
                /**
                 * generate_after_mobile_menu_button hook
                 *
                 * @since 3.0.0
                 */
                do_action( 'generate_after_mobile_menu_button' );

                wp_nav_menu(
                    array(
                        'theme_location' => 'primary',
                        'container'       => 'div', 
                        'container_class' => 'expanded-menu',
                        'menu_class' => '',
                        'fallback_cb' => 'generate_menu_fallback',
                        'walker'         => new Primary_Walker_Nav_Menu(),
                        // 'items_wrap' => '%3$s', // Do not include ul wrap, use only '%3$s' specifier
                        'items_wrap'  => '<ul class="expanded-menu-grid"><div class="expanded-menu-section mobile-only"><strong class="expanded-menu-section-header"><a class="expanded-menu-section-header-link js-event-hm-menu" href="/">Home</a></strong></div>%3$s</ul>'
                    )
                );

                /**
                 * generate_after_primary_menu hook.
                 *
                 * @since 2.3
                 */
                do_action( 'generate_after_primary_menu' );
                ?>
        </nav></div></cagov-navoverlay>
        <?php
        /**
         * generate_after_navigation hook.
         *
         * @since 3.0.0
         */
        do_action( 'generate_after_navigation' );
    }
}

if ( ! function_exists( 'generate_menu_fallback' ) ) {
    /**
     * Menu fallback.
     *
     * @since 1.1.4
     *
     * @param array $args Existing menu args.
     */
    function generate_menu_fallback( $args ) {
        $generate_settings = wp_parse_args(
            get_option( 'generate_settings', array() ),
            generate_get_defaults()
        );
        ?>
        <div id="primary-menu" class="main-nav">
            <ul <?php generate_do_element_classes( 'menu' ); ?>>
                <?php
                $args = array(
                    'sort_column' => 'menu_order',
                    'title_li' => '',
                    'walker' => new Generate_Page_Walker(),
                );

                wp_list_pages( $args );

                if ( ! generate_is_using_flexbox() && 'enable' === $generate_settings['nav_search'] ) {
                    $search_item = apply_filters(
                        'generate_navigation_search_menu_item_output',
                        sprintf(
                            '<li class="search-item menu-item-align-right"><a aria-label="%1$s" href="#">%2$s</a></li>',
                            esc_attr__( 'Open Search Bar', 'generatepress' ),
                            generate_get_svg_icon( 'search', true ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in function.
                        )
                    );

                    echo $search_item; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe output.
                }
                ?>
            </ul>
        </div>
        <?php
    }
}

/**
 * Walker menu (for main navigation)
 */
class Primary_Walker_Nav_Menu extends Walker_Nav_Menu {
    function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
         if (array_search('menu-item-has-children', $item->classes)) {
              $output .= sprintf("\n<li class='expanded-menu-col js-cagov-navoverlay-expandable expanded-menu-section %s'><div class='expanded-menu-section'><strong class='expanded-menu-section-header'><button href='%s' class=\"expanded-menu-section-header-link js-event-hm-menu\" data-toggle=\"dropdown\" >%s <span class='expanded-menu-section-header-arrow'>
              <svg width='11' height='7' class='expanded-menu-section-header-arrow-svg' viewBox='0 0 11 7' fill='none' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' clip-rule='evenodd' d='M1.15596 0.204797L5.49336 5.06317L9.8545 0.204797C10.4293 -0.452129 11.4124 0.625368 10.813 1.28143L5.90083 6.82273C5.68519 7.05909 5.32606 7.05909 5.1342 6.82273L0.174341 1.28143C-0.400433 0.6245 0.581838 -0.452151 1.15661 0.204797H1.15596Z' />
              </svg></span></button></strong></div>\n", ( array_search('current-menu-item', $item->classes) || array_search('current-page-parent', $item->classes) ) ? 'active' : '', $item->url, $item->title
              );
         } else {
              $output .= sprintf("\n<li class='expanded-menu-col js-cagov-navoverlay-expandable %s'><div class='expanded-menu-section'><strong class='expanded-menu-section-header'><a class='expanded-menu-section-header-link js-event-hm-menu' href='%s'>%s</a></strong></div>\n", ( array_search('current-menu-item', $item->classes) ) ? ' class="active"' : '', $item->url, $item->title
              );
         }
    }

    function start_lvl(&$output, $depth) {
         $indent = str_repeat("\t", $depth);
         $output .= "\n$indent<ul class=\"expanded-menu-dropdown\" role=\"menu\">\n";
    }
}

UPDATE AGENCY FOOTER. Add following functions to functions.php

if ( ! function_exists( 'generate_construct_footer_widgets' ) ) {
    add_action( 'generate_footer', 'generate_construct_footer_widgets', 5 );
    /**
     * Build our footer widgets.
     *
     * @since 1.3.42
     */
    function generate_construct_footer_widgets() {
        // Get how many widgets to show.
        $widgets = generate_get_footer_widgets();

        if ( ! empty( $widgets ) && 0 !== $widgets ) :

            // If no footer widgets exist, we don't need to continue.
            if ( ! is_active_sidebar( 'footer-1' ) && ! is_active_sidebar( 'footer-2' ) && ! is_active_sidebar( 'footer-3' ) && ! is_active_sidebar( 'footer-4' ) && ! is_active_sidebar( 'footer-5' ) ) {
                return;
            }

            // Set up the widget width.
            $widget_width = '';

            if ( 1 === (int) $widgets ) {
                $widget_width = '100';
            }

            if ( 2 === (int) $widgets ) {
                $widget_width = '50';
            }

            if ( 3 === (int) $widgets ) {
                $widget_width = '33';
            }

            if ( 4 === (int) $widgets ) {
                $widget_width = '25';
            }

            if ( 5 === (int) $widgets ) {
                $widget_width = '20';
            }
            ?>
            <section aria-label="agency footer" class="agency-footer">
    <div class="container">
     <div class="footer-logo">
     <?php generate_construct_logo(); ?>
        </div>
                        <?php
                        if ( $widgets >= 1 ) {
                            generate_do_footer_widget( $widget_width, 1 );
                        }

                        if ( $widgets >= 2 ) {
                            generate_do_footer_widget( $widget_width, 2 );
                        }

                        if ( $widgets >= 3 ) {
                            generate_do_footer_widget( $widget_width, 3 );
                        }

                        if ( $widgets >= 4 ) {
                            generate_do_footer_widget( $widget_width, 4 );
                        }

                        if ( $widgets >= 5 ) {
                            generate_do_footer_widget( $widget_width, 5 );
                        }
                        ?>
                </div>
            </div>
            <?php
        endif;

        /**
         * generate_after_footer_widgets hook.
         *
         * @since 0.1
         */
        do_action( 'generate_after_footer_widgets' );
    }
}

UPDATE STATEWIDE FOOTER. Add following functions to functions.php

if ( ! function_exists( 'generate_construct_footer' ) ) {
    add_action( 'generate_footer', 'generate_construct_footer' );
    /**
     * Build our footer.
     *
     * @since 1.3.42
     */
    function generate_construct_footer() {
        ?>
<footer>
<cagov-back-to-top data-hide-after="1000" data-label="Back to top">
    </cagov-back-to-top>
    <div class="bg-light-grey">
        <div class="container">
         <a href="https://ca.gov" class="cagov-logo" title="ca.gov" rel="noopener noreferrer" target="_blank">
        <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
          width="34px" height="34px" viewBox="0 0 44 34" style="enable-background:new 0 0 44 34;" xml:space="preserve">

          <path class="ca" d="M27.4,14c0.1-0.4,0.4-1.5,0.9-3.2c0.1-0.5,0.4-1.3,0.9-2.7c0.5-1.4,0.9-2.5,1.2-3.3c-0.9,0.6-1.8,1.4-2.7,2.3
      c-3.2,3.5-6.9,7.6-8.3,9.8c0.5-0.1,1.5-1.2,4.7-2.3C26.3,14,27.4,14,27.4,14L27.4,14z M26.9,16.2c-10.1,0-14.5,16.1-21.6,16.1
      c-1.6,0-2.8-0.7-3.7-2.1c-0.6-0.9-0.8-2-0.8-3.1c0-2.9,1.4-6.7,4.2-11.1c2.4-3.8,4.9-6.9,7.5-9.2c2.3-2,4.2-3,5.9-3
      c0.9,0,1.6,0.3,2.1,1C20.8,5.2,21,5.8,21,6.5c0,1.3-0.4,2.8-1.3,4.5c-0.8,1.5-1.7,2.8-2.9,3.9c-0.8,0.8-1.4,1.1-1.8,1.1
      c-0.3,0-0.6-0.1-0.8-0.4c-0.2-0.2-0.3-0.4-0.3-0.7c0-0.5,0.4-1,1.2-1.6c1.2-0.9,2.1-1.8,2.8-2.9c1-1.5,1.5-2.8,1.5-3.8
      c0-0.4-0.1-0.7-0.3-0.9c-0.2-0.2-0.5-0.3-0.8-0.3c-0.7,0-1.8,0.5-3.2,1.6c-1.6,1.2-3.2,2.9-5,5C8,14.8,6.3,17.4,5.2,20
      c-1.2,2.7-1.8,5-1.8,6.9c0,0.9,0.3,1.7,0.8,2.3c0.6,0.7,1.3,1.1,2.1,1.1c3.2-0.1,7.2-7.4,8.4-9.1C27,4.3,27.9,4.3,29.8,2.5
      c1.1-1,1.9-1.6,2.5-1.6c0.4,0,0.7,0.1,0.9,0.4c0.2,0.3,0.3,0.5,0.3,0.9c0,0.4-0.2,1-0.6,2c-0.7,1.7-1.3,3.5-1.9,5.4
      c-0.5,1.7-0.9,3-1,3.9c0.2,0,0.4,0,0.5,0c0.4,0,0.7,0,1,0c0.8,0,1.2,0.3,1.2,0.9c0,0.3-0.1,0.5-0.3,0.8c-0.2,0.3-0.4,0.4-0.6,0.5
      c-0.1,0-0.3,0-0.7,0c-0.8,0-1.4,0-1.7,0.1c-0.1,0.4-0.5,4.1-1.1,4.2C26.7,21.5,26.8,16.7,26.9,16.2L26.9,16.2z" />
          <g>
            <path class="gov"
              d="M16.8,27.2c0.4,0,0.8,0.2,1.1,0.5c0.3,0.3,0.5,0.7,0.5,1.1c0,0.4-0.2,0.8-0.5,1.1c-0.3,0.3-0.7,0.5-1.1,0.5
          c-0.4,0-0.8-0.2-1.1-0.5c-0.3-0.3-0.5-0.7-0.5-1.1c0-0.4,0.2-0.8,0.5-1.1C16,27.4,16.4,27.2,16.8,27.2L16.8,27.2z" />
            <path class="gov" d="M26.7,22.9l-1.1,1.1c-0.7-0.8-1.5-1.1-2.5-1.1c-0.8,0-1.5,0.3-2.1,0.8c-0.6,0.6-0.8,1.2-0.8,2
          c0,0.8,0.3,1.5,0.9,2.1c0.6,0.6,1.3,0.8,2.2,0.8c0.6,0,1-0.1,1.4-0.3c0.4-0.2,0.7-0.6,0.9-1.1h-2.4v-1.5h4.2l0,0.4
          c0,0.7-0.2,1.4-0.6,2.1c-0.4,0.7-0.9,1.2-1.5,1.5c-0.6,0.3-1.3,0.5-2.1,0.5c-0.9,0-1.7-0.2-2.3-0.6c-0.7-0.4-1.2-0.9-1.6-1.6
          c-0.4-0.7-0.6-1.5-0.6-2.3c0-1.1,0.4-2.1,1.1-2.9c0.9-1,2-1.5,3.4-1.5c0.7,0,1.4,0.1,2.1,0.4C25.7,22,26.2,22.4,26.7,22.9
          L26.7,22.9z" />
            <path class="gov" d="M32.2,21.4c1.2,0,2.2,0.4,3.1,1.3c0.9,0.9,1.3,1.9,1.3,3.2c0,1.2-0.4,2.3-1.3,3.1c-0.8,0.9-1.9,1.3-3.1,1.3
          c-1.3,0-2.3-0.4-3.2-1.3c-0.8-0.9-1.3-1.9-1.3-3.1c0-0.8,0.2-1.5,0.6-2.2c0.4-0.7,0.9-1.2,1.6-1.6C30.7,21.5,31.4,21.4,32.2,21.4
          L32.2,21.4z M32.2,22.9c-0.8,0-1.4,0.3-2,0.8c-0.5,0.5-0.8,1.2-0.8,2.1c0,0.9,0.3,1.7,1,2.2c0.5,0.4,1.1,0.6,1.8,0.6
          c0.8,0,1.4-0.3,1.9-0.8c0.5-0.6,0.8-1.2,0.8-2c0-0.8-0.3-1.5-0.8-2C33.6,23.2,33,22.9,32.2,22.9L32.2,22.9z" />
            <polygon class="gov" points="36.3,21.6 38,21.6 40.1,27.6 42.2,21.6 43.9,21.6 40.8,30 39.3,30 36.3,21.6  " />
          </g>
        </svg>
      </a>
                <?php
                /**
                 * generate_before_copyright hook.
                 *
                 * @since 0.1
                 *
                 * @hooked generate_footer_bar - 15
                 */
                do_action( 'generate_before_copyright' );
                ?>

        </div><!--container-->
        <div class="container pt-0">
                <p class="copyright">Copyright © 2021 State of California</p>
    </div><!--container-->
    </div><!--bg-light-grey-->
</footer>
        <?php
    }
}

UPDATE MAIN CONTENT.

  1. Add following functions to functions.php

/**
 * CADesignSystem Breadcrumb
 *
 * @todo update function to render web component if we build it OR export compiled breadcrumb markup or JSON to WP API
 *
 * @return HTML
 */
function cagov_breadcrumb()
{
    /* Quick breadcrumb function */

    global $post;

    $separator = "<span class=\"crumb separator\">/</span>";
    $linkOff = true;

    $items = wp_get_nav_menu_items('header-menu');

    if ($items !== "undefined" && isset($items)) {
        if (is_array($items) || is_object($items)) {
            _wp_menu_item_classes_by_context($items); // Set up the class variables, including current-classes

            $crumbs = array(
                "<a class=\"crumb\" href=\"https:\/\/ca.gov\" title=\"CA.GOV\">CA.GOV</a>",
                "<a class=\"crumb\" href=\"/\" title=\"" . get_bloginfo('name') . "\">" . get_bloginfo('name') . "</a>"
            );

            foreach ($items as $item) {
                if ($item->current_item_ancestor) {
                    if ($linkOff == true) {
                        $crumbs[] = "<span class=\"crumb\">{$item->title}</span>";
                    } else {
                        $crumbs[] = "<a class=\"crumb\" href=\"{$item->url}\" title=\"{$item->title}\">{$item->title}</a>";
                    }
                } else if ($item->current) {
                    $crumbs[] = "<span class=\"crumb current\">{$item->title}</span>";
                }
            }

            if (is_category()) {
                global $wp_query;
                $category = get_category(get_query_var('cat'), false);
                $crumbs[] = "<span class=\"crumb current\">{$category->name}</span>";
            }

            // Configuration note: requires that a menu item link to a category page.
            if (count($crumbs) == 2 && !is_category()) {
                $category = get_the_category($post->ID);

                // Get category menu item from original menu item
                $category_menu_item_found = false;

                foreach ($items as $category_item) {
                    if (isset($category_item->type_label) && $category_item->type_label === "Category") { // or ->type == "taxonomy"
                        if (isset($category[0]->name) && $category[0]->name == $category_item->title) {
                            $crumbs[] = "<span class=\"crumb current\">" . $category_item->title . "</span>";
                            $category_menu_item_found = true;
                        }
                    }
                }

                // If not found, just use the category name
                if (isset($category[0]) && $category[0] && $category_menu_item_found == false) {
                    $crumbs[] = "<span class=\"crumb current\">" . $category[0]->name . "</span>";
                }
            }

            echo '<div class="breadcrumb" aria-label="Breadcrumb" role="region">' . implode($separator, $crumbs) . '</div>';
        }
    }
}

/**
 * CADesignSystem Content Menu
 *
 * @category add_action( 'caweb_pre_footer', 'cagov_content_menu' );
 * @return HTML
 */
function cagov_content_menu()
{
    $nav_links = '';

    /* loop thru and create a link (parent nav item only) */
    $nav_menus = get_nav_menu_locations();

    if (!isset($nav_menus['content-menu'])) {
        return;
    }
?>
    <div class="per-page-feedback-container">
        <cagov-feedback data-endpoint-url="https://fa-go-feedback-001.azurewebsites.net/sendfeedback"></cagov-feedback>
    </div>
    <div class="content-footer-container">
        <div class="content-footer">
            <div class="menu-section">
                <div class="logo-small">
                </div>
            </div>
            <div class="menu-section">
                <ul class="content-menu-links">
                    <?php
                    $menuitems = wp_get_nav_menu_items($nav_menus['content-menu']);

                    foreach ($menuitems as $item) {
                        if (!$item->menu_item_parent) {
                            $class  = !empty($item->classes) ? implode(' ', $item->classes) : '';
                            $rel    = !empty($item->xfn) ? $item->xfn : '';
                            $target = !empty($item->target) ? $item->target : '_blank';
                    ?>
                            <li class="<?php echo esc_attr($class); ?>" title="<?php echo esc_attr($item->attr_title); ?>" rel="<?php echo esc_attr($rel); ?>">
                                <a href="<?php echo esc_url($item->url); ?>" target="<?php echo esc_attr($target); ?>"><?php echo esc_attr($item->title); ?></a>
                            </li>
                    <?php
                        }
                    }
                    ?>
                </ul>
            </div>
            <div class="menu-section menu-section-social">
                <?php
                cagov_content_social_menu();
                ?>
            </div>
        </div>
    </div>
<?php
}
  1. Update main content containers attributes. Open header.php and use this code:
    
    <?php
    /**
    * The template for displaying the header.
    *
    * @package GeneratePress
    */

if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. }

?><!DOCTYPE html> <html <?php language_attributes(); ?>>

<body <?php body_class(); ?> <?php generate_do_microdata( 'body' ); ?>> <?php /**



## UPDATE CHANGELOG.md, README.md, ROADMAP.md, style.css (version #)
kkoryaka commented 2 years ago

Was able to adapt design system locally, now I need to create child theme and put it into the some repo:

Screen Shot 2021-11-17 at 4 32 56 PM

chachasikes commented 2 years ago

Archiving / closing.

We did a lot of work on this and created an alternate theme in order to help validate what needs to go forward into the CAWeb theme.

Work is starting to pick up on this by CDT and expect this effort to be rescoped, so closing.