Skip to content

Commit

Permalink
Add theme hook form_required_marker (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenoh authored Dec 5, 2023
1 parent 30f5c82 commit 5be4110
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Theme/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ protected function processExtension(array &$cache, $name, $type, $theme, $path):
$cache[$theme_hook]['path'] = '@retrofit';
}
}

$cache['form_required_marker'] = [
'render element' => 'element',
'type' => 'module',
'template' => 'theme-function',
'path' => '@retrofit',
];
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/functions/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,16 @@ function form_get_errors()
return $form;
}
}

/**
* @param mixed[] $variables
*/
function theme_form_required_marker(array $variables): string
{
$attributes = [
'class' => ['form-item__label', 'form-required'],
'style' => 'display: inline',
'title' => (string) t('This field is required.'),
];
return '<span' . drupal_attributes($attributes) . '></span>';
}

0 comments on commit 5be4110

Please sign in to comment.