Skip to content

Commit

Permalink
Merge pull request #497 from danskernesdigitalebibliotek/DDFFORM-9-by…
Browse files Browse the repository at this point in the history
…line-dato-og-forfatter-e

Add Byline to `Article` Content-Type
  • Loading branch information
kasperbirch1 authored Nov 29, 2023
2 parents 6b4cb62 + 1a2d85b commit 3eeeabd
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 8 deletions.
18 changes: 17 additions & 1 deletion config/sync/config_ignore.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,39 @@ ignored_config_entities:
- ~block.block.gin_primary_local_tasks
- ~block.block.gin_secondary_local_tasks
- ~config_ignore.settings
- '~core.date_format.*'
- '~core.base_field_override.node.article.*'
- '~core.base_field_override.node.campaign.*'
- '~core.base_field_override.node.event.*'
- '~core.date_format.*'
- '~core.entity_form_display.node.article.*'
- '~core.entity_form_display.node.campaign.*'
- '~core.entity_form_display.node.event.*'
- '~core.entity_form_display.paragraph.campaign_rule.*'
- '~core.entity_form_mode.user_register.*'
- '~core.entity_view_display.node.article.*'
- '~core.entity_view_display.node.campaign.*'
- '~core.entity_view_display.node.event.*'
- '~core.entity_view_display.paragraph.campaign_rule.*'
- '~core.entity_view_mode.display.*'
- '~core.entity_view_mode.node.*'
- '~core.entity_view_mode.paragraph.*'
- ~core.date_format.date_full_month
- ~core.menu.static_menu_link_overrides
- ~dblog.settings
- '~dpl_library_agency.general_settings:reservation_sms_notifications_disabled'
- '~dpl_mapp.settings:domain'
- '~field.field.node.campaign.*'
- '~field.field.paragraph.campaign_rule.*'
- ~field.field.node.article.field_override_author
- ~field.field.node.article.field_show_override_author
- ~field.field.node.article.field_subtitle
- ~field.settings
- ~field.storage.node.body
- ~field.storage.node.field_campaign_image
- ~field.storage.node.field_campaign_rules
- ~field.storage.node.field_override_author
- ~field.storage.node.field_show_override_author
- ~field.storage.node.field_subtitle
- ~field.storage.paragraph.field_campaign_rule_facet
- ~field.storage.paragraph.field_campaign_rule_term
- ~field.storage.paragraph.field_campaign_rule_term_ranking
Expand All @@ -58,10 +68,12 @@ ignored_config_entities:
- ~language.entity.zxx
- ~language.mappings
- ~language.negotiation
- ~language.content_settings.node.article
- ~language.types
- ~locale.settings
- ~node.settings
- ~node.type.campaign
- ~node.type.article
- ~node.type.event
- ~paragraphs.paragraphs_type.campaign_rule
- ~paragraphs.settings
Expand Down Expand Up @@ -110,6 +122,10 @@ ignored_config_entities:
- ~favorites_list.settings
- ~varnish_purger.settings.65fc931232
- ~varnish_purger.settings.30cd45a1b1
- ~views.settings
- ~views.view.content
- ~views.view.files
- ~views.view.user_admin_people
- ~dpl_loan_list.settings
- ~dpl_fees.settings
- ~dpl_recommender.settings
Expand Down
8 changes: 8 additions & 0 deletions config/sync/core.date_format.date_full_month.yml
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'
17 changes: 17 additions & 0 deletions config/sync/core.entity_form_display.node.article.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ langcode: en
status: true
dependencies:
config:
- field.field.node.article.field_override_author
- field.field.node.article.field_paragraphs
- field.field.node.article.field_show_override_author
- field.field.node.article.field_subtitle
- node.type.article
module:
Expand All @@ -15,6 +17,14 @@ targetEntityType: node
bundle: article
mode: default
content:
field_override_author:
type: string_textfield
weight: 5
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_paragraphs:
type: paragraphs
weight: 2
Expand Down Expand Up @@ -43,6 +53,13 @@ content:
add_in_between_link_count: 0
delete_confirmation: true
show_drag_and_drop: true
field_show_override_author:
type: boolean_checkbox
weight: 4
region: content
settings:
display_label: true
third_party_settings: { }
field_subtitle:
type: string_textarea
weight: 1
Expand Down
20 changes: 20 additions & 0 deletions config/sync/core.entity_view_display.node.article.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ langcode: en
status: true
dependencies:
config:
- field.field.node.article.field_override_author
- field.field.node.article.field_show_override_author
- field.field.node.article.field_subtitle
- node.type.article
module:
Expand All @@ -12,6 +14,24 @@ targetEntityType: node
bundle: article
mode: default
content:
field_override_author:
type: string
label: above
settings:
link_to_entity: false
third_party_settings: { }
weight: 106
region: content
field_show_override_author:
type: boolean
label: above
settings:
format: default
format_custom_false: ''
format_custom_true: ''
third_party_settings: { }
weight: 107
region: content
field_subtitle:
type: basic_string
label: above
Expand Down
4 changes: 4 additions & 0 deletions config/sync/core.entity_view_display.node.article.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ status: true
dependencies:
config:
- core.entity_view_mode.node.full
- field.field.node.article.field_override_author
- field.field.node.article.field_show_override_author
- field.field.node.article.field_subtitle
- field.field.node.article.field_paragraphs
- node.type.article
Expand Down Expand Up @@ -37,5 +39,7 @@ content:
weight: 1
region: content
hidden:
field_override_author: true
field_show_override_author: true
langcode: true
links: true
4 changes: 4 additions & 0 deletions config/sync/core.entity_view_display.node.article.teaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ status: false
dependencies:
config:
- core.entity_view_mode.node.teaser
- field.field.node.article.field_override_author
- field.field.node.article.field_show_override_author
- field.field.node.article.field_subtitle
- node.type.article
module:
Expand All @@ -19,6 +21,8 @@ content:
weight: 100
region: content
hidden:
field_override_author: true
field_paragraphs: true
field_show_override_author: true
field_subtitle: true
langcode: true
1 change: 1 addition & 0 deletions config/sync/core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module:
config_filter: 0
config_ignore: 0
customerror: 0
dpl_article: 0
dpl_campaign: 0
dpl_dashboard: 0
dpl_favorites_list: 0
Expand Down
19 changes: 19 additions & 0 deletions config/sync/field.field.node.article.field_override_author.yml
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
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
21 changes: 21 additions & 0 deletions config/sync/field.storage.node.field_override_author.yml
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 config/sync/field.storage.node.field_show_override_author.yml
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
2 changes: 1 addition & 1 deletion config/sync/node.type.article.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ description: 'Use articles for news-worthy content, that does not get updated re
help: ''
new_revision: false
preview_mode: 0
display_submitted: false
display_submitted: true
5 changes: 5 additions & 0 deletions web/modules/custom/dpl_article/dpl_article.info.yml
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
57 changes: 57 additions & 0 deletions web/modules/custom/dpl_article/dpl_article.module
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]],
];
}
}
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 %}
5 changes: 5 additions & 0 deletions web/themes/custom/novel/templates/fields/username.html.twig
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 -%}
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>

0 comments on commit 3eeeabd

Please sign in to comment.