Skip to content
Snippets Groups Projects
Commit eeddd1df authored by Tobias Bähr's avatar Tobias Bähr
Browse files

Issue #3400138: Allow to hide components of PageTitleBlock

parent e0592fe6
Branches
Tags
No related merge requests found
......@@ -17,4 +17,7 @@ settings:
label: 'Page title with subtitle'
label_display: '0'
provider: openculturas_custom
subheadline_display: true
subtype_display: true
profilepicture_display: true
visibility: { }
......@@ -16,4 +16,7 @@ settings:
label: 'Page title with subtitle'
label_display: '0'
provider: openculturas_custom
subheadline_display: true
subtype_display: true
profilepicture_display: true
visibility: { }
......@@ -35,3 +35,17 @@ openculturas_custom.settings:
type: string
label: 'Label of class'
block.settings.openculturas_custom_page_title:
type: block_settings
label: 'Page title block'
mapping:
subheadline_display:
type: boolean
label: 'Subheadline (tagline)'
subtype_display:
type: boolean
label: 'Sub type'
profilepicture_display:
type: boolean
label: 'Profile picture'
......@@ -9,6 +9,7 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\openculturas_custom\CurrentEntityHelper;
......@@ -68,7 +69,57 @@ public function setTitle($title): PageTitleBlock {
* @php-return array{label_display: false}
*/
public function defaultConfiguration(): array {
return ['label_display' => FALSE];
return [
'label_display' => FALSE,
'subheadline_display' => TRUE,
'subtype_display' => TRUE,
'profilepicture_display' => TRUE,
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state): array {
$form = parent::buildConfigurationForm($form, $form_state);
$form['page_title_block'] = [
'#type' => 'details',
'#title' => $this->t('Components'),
'#open' => TRUE,
'#description' => $this->t('The default page title block compose several fields. Deselect here what you prefer to place elsewhere in the layout.'),
];
$form['page_title_block']['page_title_display'] = [
'#title' => $this->t('Page title'),
'#type' => 'checkbox',
'#disabled' => TRUE,
'#default_value' => TRUE,
];
$form['page_title_block']['subheadline_display'] = [
'#title' => $this->t('Subheadline (tagline)'),
'#type' => 'checkbox',
'#default_value' => $this->configuration['subheadline_display'],
];
$form['page_title_block']['subtype_display'] = [
'#title' => $this->t('Sub type'),
'#type' => 'checkbox',
'#default_value' => $this->configuration['subtype_display'],
];
$form['page_title_block']['profilepicture_display'] = [
'#title' => $this->t('Profile picture'),
'#type' => 'checkbox',
'#default_value' => $this->configuration['profilepicture_display'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state): void {
$this->configuration['subheadline_display'] = $form_state->getValue(['page_title_block', 'subheadline_display']);
$this->configuration['subtype_display'] = $form_state->getValue(['page_title_block', 'subtype_display']);
$this->configuration['profilepicture_display'] = $form_state->getValue(['page_title_block', 'profilepicture_display']);
parent::blockSubmit($form, $form_state);
}
/**
......@@ -92,15 +143,15 @@ public function build(): array {
$current_entity = $this->entityRepository->getTranslationFromContext($current_entity);
$title_markup[] = ['#plain_text' => $current_entity->label()];
$this->title = $title_markup;
if ($current_entity->hasField('field_subtitle')
if ($this->configuration['subheadline_display'] && $current_entity->hasField('field_subtitle')
&& !$current_entity->get('field_subtitle')->isEmpty()) {
$subtitle = $current_entity->get('field_subtitle')->view(['label' => 'hidden']);
}
if ($current_entity->hasField('field_sub_type')
if ($this->configuration['subtype_display'] && $current_entity->hasField('field_sub_type')
&& !$current_entity->get('field_sub_type')->isEmpty()) {
$sub_type = $current_entity->get('field_sub_type')->view(['label' => 'hidden']);
}
if ($current_entity->hasField('field_portrait')
if ($this->configuration['profilepicture_display'] && $current_entity->hasField('field_portrait')
&& !$current_entity->get('field_portrait')->isEmpty()) {
$display_options = [
'type' => 'entity_reference_entity_view',
......
......@@ -19,11 +19,11 @@
{% endif %}
{{ profile_image }}
<div class="headlines-wrapper">
{% if sub_type.0 %}
{% if sub_type and sub_type.0 %}
<div class="sub-type field__label">{{ sub_type.0 }}</div>
{% endif %}
<h1{{ title_attributes.addClass('page-title') }}>{{ title }}</h1>
{% if subtitle.0 %}
{% if subtitle and subtitle.0 %}
<h2 class="page-subtitle">{{ subtitle.0 }}</h2>
{% endif %}
</div>
......
......@@ -15,11 +15,11 @@ function openculturas_base_form_system_theme_settings_alter(array &$form, FormSt
return;
}
$form['custom_settings'] = [
$form['background_image'] = [
'#type' => 'details',
'#title' => t('Background image'),
];
$form['custom_settings']['background_image_mode'] = [
$form['background_image']['background_image_mode'] = [
'#type' => 'radios',
'#default_value' => theme_get_setting('background_image.mode') ?? 'mood_image',
'#description' => t('An image can be appended behind the content to cover the viewport background.'),
......@@ -29,7 +29,7 @@ function openculturas_base_form_system_theme_settings_alter(array &$form, FormSt
'global_image' => t('Use global image globally (upload here)'),
],
];
$form['custom_settings']['background_image_path'] = [
$form['background_image']['background_image_path'] = [
'#type' => 'textfield',
'#title' => t('Path to custom background image'),
'#default_value' => theme_get_setting('background_image.path'),
......@@ -40,7 +40,7 @@ function openculturas_base_form_system_theme_settings_alter(array &$form, FormSt
],
];
$element = &$form['custom_settings']['background_image_path'];
$element = &$form['background_image']['background_image_path'];
$friendly_path = NULL;
$original_path = $element['#default_value'];
$default = 'background.jpg';
......@@ -54,7 +54,7 @@ function openculturas_base_form_system_theme_settings_alter(array &$form, FormSt
'@explicit-file' => is_string($original_path) && StreamWrapperManager::getScheme($original_path) !== FALSE ? $original_path : 'public://' . $default,
]);
$form['custom_settings']['background_image_upload'] = [
$form['background_image']['background_image_upload'] = [
'#type' => 'file',
'#title' => t('Upload background image'),
'#description' => t("If you don't have direct file access to the server, use this field to upload your image."),
......@@ -76,8 +76,8 @@ function openculturas_base_form_system_theme_settings_alter(array &$form, FormSt
* Validation handler for openculturas_base_form_system_theme_settings_alter().
*/
function openculturas_base_form_system_theme_settings_validate(array &$form, FormStateInterface $form_state): void {
if (isset($form['custom_settings']['background_image_upload'])) {
$file = _file_save_upload_from_form($form['custom_settings']['background_image_upload'], $form_state, 0);
if (isset($form['background_image']['background_image_upload'])) {
$file = _file_save_upload_from_form($form['background_image']['background_image_upload'], $form_state, 0);
if ($file) {
// Put the temporary file in form_values, so we can save it on submit.
$form_state->setValue('background_image_upload', $file);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment