Skip to content

Commit

Permalink
Merge pull request #3 from visual-framework/feature/query-group-conte…
Browse files Browse the repository at this point in the history
…nthub-profile

Begin update of vf-header template, pull in short and long descrip
  • Loading branch information
khawkins98 authored May 2, 2019
2 parents 29203bf + 68b72f5 commit 1460bf5
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 9 deletions.
13 changes: 13 additions & 0 deletions wp-content/plugins/embl-taxonomy/embl-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ function embl_taxonomy_get_term($term_id) {
return null;
}

/**
* Return uuid associated with a WordPress taxonomy term
*/
function embl_taxonomy_get_uuid($term_id) {
$term = embl_taxonomy_get_term($term_id);
if ( ! $term->meta ) {
return null;
}
$uuid = end($term->meta['embl_taxonomy_ids']);
return $uuid;
}


/**
* Return the VF stylesheet URL
*/
Expand Down
4 changes: 4 additions & 0 deletions wp-content/plugins/vf-group-header-block/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

A textual introduction aside a group leader using the `vf-summary--profile` Visual Framework pattern.

If a header post is not available in the VF Blocks (or is blank), this plugin will try to use the EMBL Who taxonomy term and pull the group description from the ContentHub.

A "read more" to the about page will automatically be appended.

## Configuration

Related post:
Expand Down
19 changes: 19 additions & 0 deletions wp-content/plugins/vf-group-header-block/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@
$heading
);

// if heading is empty, use the contenthub description
if (vf_html_empty($heading)) {
if ( class_exists('VF_Cache') ) {
$uuid = vf__get_site_uuid();
$heading = '<h1 class="vf-lede">' . VF_Cache::get_post('https://dev.beta.embl.org/api/v1/pattern.html?filter-content-type=profiles&filter-uuid='.$uuid.'&pattern=node-teaser&source=contenthub') . '</h1>';
$heading = preg_replace(
'#<p>#',
'<h1 class="vf-lede">',
$heading
);
$heading = preg_replace(
'#</p>#',
' <a class="vf-link" href="'.get_site_url().'/about">Read more</a>.</h1>',
$heading
);
}
}


$content = $vf_plugin->api_html();

?>
Expand Down
25 changes: 25 additions & 0 deletions wp-content/themes/vf-wp/functions/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,29 @@ function vf__nav_menu_link_attributes($atts, $item, $args, $depth) {
return $atts;
}


/**
* Shorthand to safely query the UUID of the active "who" term, if set
*/
function vf__get_site_uuid() {

// first we want to be sure the taxonomy plugin is enabled
if ( ! function_exists('embl_taxonomy_get_uuid')) {
print '<!-- To get the UUID, you must enable the EMBL Taxonomy plugin -->' . PHP_EOL;
return null;
}

$term_id = get_field('embl_taxonomy_term_what', 'option');

if ( ! $term_id ) {
print '<!-- If you wish to get the group UUID, you must set the group\'s "what" at /wp-admin/options-general.php?page=embl-settings -->';

}

$uuid = embl_taxonomy_get_uuid($term_id);

return $uuid;
}


?>
10 changes: 7 additions & 3 deletions wp-content/themes/vf-wp/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

the_post();

$vf_group_header = VF_Plugin::get_plugin('vf_group_header');
// Only show group long description on front page
if (is_front_page()) {

if (class_exists('VF_Group_Header')) {
VF_Plugin::render($vf_group_header);
$vf_group_header = VF_Plugin::get_plugin('vf_group_header');

if (class_exists('VF_Group_Header')) {
VF_Plugin::render($vf_group_header);
}
}

?>
Expand Down
20 changes: 14 additions & 6 deletions wp-content/themes/vf-wp/partials/vf-masthead.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<div class="vf-masthead">
<div class="vf-masthead__inner">
<div class="vf-masthead" style="background-color: var(--vf-masthead__color--background, var(--vf-masthead__color--background-default)); color: var(--vf-masthead__color--foreground, var(--vf-masthead__color--foreround-default) );">
<div class="vf-masthead__title">
<div class="vf-masthead__title-inner">
<h1 class="vf-masthead__heading | text--heading--xl">
<h1 class="vf-masthead__heading">
<a class="vf-masthead__heading__link" href="<?php echo home_url(); ?>"><?php echo esc_html(get_bloginfo('name')); ?></a>
<span class="vf-masthead__heading--additional">
<?php
if ( class_exists('VF_Cache') ) {
$uuid = vf__get_site_uuid();
$short_description = VF_Cache::get_post('https://dev.beta.embl.org/api/v1/pattern.html?filter-content-type=profiles&filter-uuid='.$uuid.'&pattern=node-strapline&source=contenthub');
// we don't want any of the contentHub `div`s. `span`s are OK though
$short_description = str_replace(array('<div', '</div>'), array('<span', '</span>'), $short_description);
print $short_description;
}
?>
</span>
</h1>
</div>
</div>
</div>
</div>

<!--/vf-masthead-->

0 comments on commit 1460bf5

Please sign in to comment.