Skip to content

Commit

Permalink
Fieldcheck (#1)
Browse files Browse the repository at this point in the history
* adds field check

* checks if node

* updates if check and fixes code formatting

---------

Co-authored-by: “Kerry <“[email protected]”>
  • Loading branch information
kmurphychi247 and “Kerry committed Jan 17, 2024
1 parent 9680772 commit 41776c6
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions saplings_custom.module
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@
function saplings_custom_preprocess_html(array &$variables) {
// Load the node entity from current route.
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof NodeInterface){
// Get the value of the field.
if ($node) {
$robots_field = $node->get('sa_robots')->getString();
}
// Only render if the field has value.
if ($robots_field) {
$variables['page']['#attached']['html_head'][] = [
[
'#tag' => 'meta',
'#attributes' => [
'name' => 'robots',
'content' => $robots_field,
if ($node->hasField('sa_robots')) {
$robots_field = $node->get('sa_robots')->getString();
}
// Only render if the field has value.
if ($robots_field) {
$variables['page']['#attached']['html_head'][] = [
[
'#tag' => 'meta',
'#attributes' => [
'name' => 'robots',
'content' => $robots_field,
],
],
],
'robots',
];
'robots',
];
}
}
}

0 comments on commit 41776c6

Please sign in to comment.