Skip to content

Added view mode name override function #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 8.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/schema/view_mode_selector.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ field.field_settings.view_mode_selector:
type: boolean
hide_title:
type: boolean
override_title:
type: string
icon:
type: mapping
mapping:
Expand Down
11 changes: 11 additions & 0 deletions src/Plugin/Field/FieldType/ViewModeSelectorItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
// if ($instance['widget']['type'] == 'view_mode_selector_radios') {
$element['view_modes'][$view_mode_id]['prefix']['#markup'] = '<div class="settings">';

$element['view_modes'][$view_mode_id]['override_title'] = [
'#type' => 'textfield',
'#title' => $this->t('Override title'),
'#default_value' => $settings['view_modes'][$view_mode_id]['override_title'] ?? "",
'#states' => [
'visible' => [
'input[name="field[settings][view_modes][' . $view_mode_id . '][enable]"]' => ['checked' => TRUE],
],
],
];

$element['view_modes'][$view_mode_id]['hide_title'] = [
'#type' => 'checkbox',
'#title' => t('Hide title'),
Expand Down
4 changes: 4 additions & 0 deletions src/Plugin/Field/FieldWidget/ViewModeSelectorWidgetBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInter
// Reduce options by enabled view modes
foreach (array_keys($view_modes) as $view_mode) {
if (isset($field_settings['view_modes'][$view_mode]['enable']) && $field_settings['view_modes'][$view_mode]['enable']) {
if (isset($field_settings['view_modes'][$view_mode]['override_title']) && strlen($field_settings['view_modes'][$view_mode]['override_title']) > 0) {
$view_modes[$view_mode] = $field_settings['view_modes'][$view_mode]['override_title'];
}

continue;
}
unset($view_modes[$view_mode]);
Expand Down