-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #497 from danskernesdigitalebibliotek/DDFFORM-9-by…
…line-dato-og-forfatter-e Add Byline to `Article` Content-Type
- Loading branch information
Showing
17 changed files
with
232 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
uuid: 978c615f-037a-422a-bdd7-f919ac256d3b | ||
langcode: da | ||
status: true | ||
dependencies: { } | ||
id: date_full_month | ||
label: 'Date full month' | ||
locked: false | ||
pattern: 'd. F Y' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
config/sync/field.field.node.article.field_override_author.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
uuid: db8e3dcc-93d1-4c4e-af0c-24dd345b1b1a | ||
langcode: en | ||
status: true | ||
dependencies: | ||
config: | ||
- field.storage.node.field_override_author | ||
- node.type.article | ||
id: node.article.field_override_author | ||
field_name: field_override_author | ||
entity_type: node | ||
bundle: article | ||
label: 'Override author' | ||
description: '' | ||
required: false | ||
translatable: false | ||
default_value: { } | ||
default_value_callback: '' | ||
settings: { } | ||
field_type: string |
23 changes: 23 additions & 0 deletions
23
config/sync/field.field.node.article.field_show_override_author.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
uuid: 273db154-2b0c-487a-b584-4cc51603c63c | ||
langcode: en | ||
status: true | ||
dependencies: | ||
config: | ||
- field.storage.node.field_show_override_author | ||
- node.type.article | ||
id: node.article.field_show_override_author | ||
field_name: field_show_override_author | ||
entity_type: node | ||
bundle: article | ||
label: "Override the author\t" | ||
description: "By default, the author is set to the Drupal user that owns the content.<br>\r\nIf you want to override this, with a manual text, you can check this." | ||
required: false | ||
translatable: false | ||
default_value: | ||
- | ||
value: 0 | ||
default_value_callback: '' | ||
settings: | ||
on_label: 'On' | ||
off_label: 'Off' | ||
field_type: boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
uuid: 23fe8692-79ae-43af-913b-60c720cf0914 | ||
langcode: en | ||
status: true | ||
dependencies: | ||
module: | ||
- node | ||
id: node.field_override_author | ||
field_name: field_override_author | ||
entity_type: node | ||
type: string | ||
settings: | ||
max_length: 255 | ||
case_sensitive: false | ||
is_ascii: false | ||
module: core | ||
locked: false | ||
cardinality: 1 | ||
translatable: true | ||
indexes: { } | ||
persist_with_no_fields: false | ||
custom_storage: false |
18 changes: 18 additions & 0 deletions
18
config/sync/field.storage.node.field_show_override_author.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
uuid: 65f21349-be77-45a4-ae4a-a69f9e29ce69 | ||
langcode: en | ||
status: true | ||
dependencies: | ||
module: | ||
- node | ||
id: node.field_show_override_author | ||
field_name: field_show_override_author | ||
entity_type: node | ||
type: boolean | ||
settings: { } | ||
module: core | ||
locked: false | ||
cardinality: 1 | ||
translatable: true | ||
indexes: { } | ||
persist_with_no_fields: false | ||
custom_storage: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: "Article" | ||
type: module | ||
description: "Functionality related to creating article content." | ||
package: "DPL" | ||
core_version_requirement: ^10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* DPL article module. | ||
*/ | ||
|
||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\node\NodeInterface; | ||
|
||
/** | ||
* Implements hook_preprocess_HOOK(). | ||
*/ | ||
function dpl_article_preprocess_node(array &$variables): void { | ||
$node = $variables['node'] ?? NULL; | ||
|
||
// Process only if the node is a valid Node entity. | ||
if (!($node instanceof NodeInterface)) { | ||
return; | ||
} | ||
|
||
// Override author name if the 'show override author' field is set. | ||
$has_override = $node->get('field_show_override_author') | ||
->getString() === '1'; | ||
if ($has_override) { | ||
$variables['author_name'] = $node->get('field_override_author') | ||
->getString(); | ||
} | ||
} | ||
|
||
/** | ||
* Implements hook_form_alter(). | ||
* | ||
* Modifies node forms to control the visibility of articles fields. | ||
* | ||
* @param array<mixed> $form | ||
* An associative array containing the structure of the form. | ||
* @param \Drupal\Core\Form\FormStateInterface $form_state | ||
* The current state of the form. | ||
* @param string $form_id | ||
* The unique identifier of the form. | ||
*/ | ||
function dpl_article_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void { | ||
// Target only article node creation or edit forms. | ||
// They follow this format: node_article_edit_form / node_article_form. | ||
if (!str_starts_with($form_id, 'node_article_') || | ||
!(str_ends_with($form_id, '_edit_form') || str_ends_with($form_id, '_form'))) { | ||
return; | ||
} | ||
|
||
// Toggle visibility of 'override author' field based on a checkbox. | ||
if (isset($form['field_show_override_author'])) { | ||
$form['field_override_author']['#states'] = [ | ||
'visible' => [':input[name="field_show_override_author[value]"]' => ['checked' => TRUE]], | ||
]; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
web/themes/custom/novel/templates/fields/field--field-subtitle.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{% for item in items %} | ||
<p{{item.attributes.addClass('text-subtitle','article-header__subtitle')}}> | ||
<p{{item.attributes.addClass('article-header__subtitle')}}> | ||
{{ item.content }} | ||
</p> | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% if link_path -%} | ||
<a{{attributes.addClass('article-header__author')}}>{{ name }}{{ extra }}</a> | ||
{%- else -%} | ||
<span{{attributes}}>{{ name }}{{ extra }}</span> | ||
{%- endif -%} |
16 changes: 11 additions & 5 deletions
16
web/themes/custom/novel/templates/layout/node--article--full.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
<article class="article"> | ||
<header class="article-header"> | ||
<h1 class="text-header-h1 article-header__title"> | ||
{{ label }} | ||
</h1> | ||
<h1 class="article-header__title">{{ label }}</h1> | ||
|
||
{{content}} | ||
{{ content.field_subtitle }} | ||
|
||
<p class="article-header__info"> | ||
{{ 'By @username'|t({'@username': author_name}) }} | ||
|
||
<time class="article-header__date"> | ||
{{ node.created.value|format_date('date_full_month') }} | ||
</time> | ||
</p> | ||
</header> | ||
|
||
{{ content }} | ||
{{ content|without('field_subtitle') }} | ||
</article> |