Skip to content

Commit

Permalink
Merge pull request #277 from localgovdrupal/1.x
Browse files Browse the repository at this point in the history
PR for 1.6.2
  • Loading branch information
andybroomfield committed Aug 8, 2023
2 parents bc8fce1 + 82ab7f9 commit c858b93
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 3 additions & 0 deletions config/install/workflows.workflow.localgov_alert_banners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ dependencies:
- localgov_alert_banner.localgov_alert_banner_type.localgov_alert_banner
module:
- content_moderation
enforced:
module:
- localgov_alert_banner
id: localgov_alert_banners
label: 'Alert banners'
type: content_moderation
Expand Down
14 changes: 14 additions & 0 deletions localgov_alert_banner.module
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,17 @@ function localgov_alert_banner_configure_scheduled_transitions() {
}
user_role_grant_permissions('emergency_publisher', $permissions);
}

/**
* Implements hook_preprocess_field().
*/
function localgov_alert_banner_preprocess_field(&$variables) {
if ($variables['element']['#field_name'] == 'link' && $variables['element']['#bundle'] == 'localgov_alert_banner') {
foreach ($variables['element']['#items'] as $item) {
if (empty($item->getValue()['title'])) {
$default_text = t('More information');
$variables['items'][0]['content']['#title'] = $default_text;
}
}
}
}
9 changes: 0 additions & 9 deletions localgov_alert_banner.page.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
* Page callback for Alert banner entities.
*/

use Drupal\Core\Link;
use Drupal\Core\Render\Element;
use Drupal\Core\Url;

/**
* Prepares variables for Alert banner templates.
Expand All @@ -33,13 +31,6 @@ function template_preprocess_localgov_alert_banner(array &$variables) {
/** @var \Drupal\localgov_alert_banner\Entity\AlertBannerEntity $entity */
$entity = $variables['elements']['#localgov_alert_banner'];

// Set default link text if field exists.
if ($entity->hasField('link')) {
if ($entity->get('link')->title === '') {
$variables['content']['link'] = Link::fromTextAndUrl(t('More information'), Url::fromUri($entity->get('link')->uri))->toString();
}
}

// Non-content variables.
$variables['display_title'] = $entity->get('display_title')->value;
$variables['remove_hide_link'] = $entity->get('remove_hide_link')->value;
Expand Down

0 comments on commit c858b93

Please sign in to comment.