Skip to content
Snippets Groups Projects

Improve hardcoding #group for the status field

Merged paul121 requested to merge issue/gin-3440148:3440148-only-status-content-form into 8.x-3.x
1 unresolved thread
+ 67
57
    • The diff for this commit is a bit ugly, but its not that complicated. This collapses the nested if statements into a single if statement and saves the conditions to a variable so they can be reused later on. Much of the diff is un-indenting all of the logic from the nested if statement.

@@ -109,81 +109,91 @@ class GinContentFormHelper implements ContainerInjectionInterface {
@@ -109,81 +109,91 @@ class GinContentFormHelper implements ContainerInjectionInterface {
return FALSE;
return FALSE;
}
}
 
// Save form types and behaviors.
 
$use_sticky_action_buttons = $this->stickyActionButtons($form, $form_state, $form_id);
 
$is_content_form = $this->isContentForm($form, $form_state, $form_id);
 
// Sticky action buttons.
// Sticky action buttons.
if ($this->stickyActionButtons($form, $form_state, $form_id) || $this->isContentForm($form, $form_state, $form_id)) {
if (($use_sticky_action_buttons || $is_content_form) && isset($form['actions'])) {
// Action buttons.
if (isset($form['actions'])) {
// Add sticky class.
$form['actions']['#attributes']['class'][] = 'gin-sticky-form-actions';
// Add a class to identify modified forms.
if (!isset($form['#attributes']['class'])) {
$form['#attributes']['class'] = [];
}
elseif (is_string($form['#attributes']['class'])) {
$form['#attributes']['class'] = [$form['#attributes']['class']];
}
$form['#attributes']['class'][] = 'gin--has-sticky-form-actions';
// Sticky action container.
// Add sticky class.
$form['gin_sticky_actions'] = [
$form['actions']['#attributes']['class'][] = 'gin-sticky-form-actions';
'#type' => 'container',
'#weight' => -1,
'#multilingual' => TRUE,
'#attributes' => [
'class' => ['gin-sticky-form-actions'],
],
];
// Create gin_more_actions group.
// Add a class to identify modified forms.
$toggle_more_actions = t('More actions');
if (!isset($form['#attributes']['class'])) {
$form['gin_sticky_actions']['more_actions'] = [
$form['#attributes']['class'] = [];
'#type' => 'container',
}
'#multilingual' => TRUE,
elseif (is_string($form['#attributes']['class'])) {
'#weight' => 998,
$form['#attributes']['class'] = [$form['#attributes']['class']];
'#attributes' => [
}
'class' => ['gin-more-actions'],
$form['#attributes']['class'][] = 'gin--has-sticky-form-actions';
],
'more_actions_toggle' => [
// Sticky action container.
'#markup' => '<a href="#toggle-more-actions" class="gin-more-actions__trigger trigger" data-gin-tooltip role="button" title="' . $toggle_more_actions . '" aria-controls="gin_more_actions"><span class="visually-hidden">' . $toggle_more_actions . '</span></a>',
$form['gin_sticky_actions'] = [
'#weight' => 1,
'#type' => 'container',
],
'#weight' => -1,
'more_actions_items' => [
'#multilingual' => TRUE,
'#type' => 'container',
'#attributes' => [
'#multilingual' => TRUE,
'class' => ['gin-sticky-form-actions'],
],
],
];
];
// Assign status to gin_actions.
// Create gin_more_actions group.
$form['gin_sticky_actions']['status'] = [
$toggle_more_actions = t('More actions');
 
$form['gin_sticky_actions']['more_actions'] = [
 
'#type' => 'container',
 
'#multilingual' => TRUE,
 
'#weight' => 998,
 
'#attributes' => [
 
'class' => ['gin-more-actions'],
 
],
 
'more_actions_toggle' => [
 
'#markup' => '<a href="#toggle-more-actions" class="gin-more-actions__trigger trigger" data-gin-tooltip role="button" title="' . $toggle_more_actions . '" aria-controls="gin_more_actions"><span class="visually-hidden">' . $toggle_more_actions . '</span></a>',
 
'#weight' => 1,
 
],
 
'more_actions_items' => [
'#type' => 'container',
'#type' => 'container',
'#weight' => -1,
'#multilingual' => TRUE,
'#multilingual' => TRUE,
];
],
 
];
 
 
// Assign status to gin_actions.
 
$form['gin_sticky_actions']['status'] = [
 
'#type' => 'container',
 
'#weight' => -1,
 
'#multilingual' => TRUE,
 
];
 
 
// Only alter the status field on content forms.
 
if ($is_content_form) {
// Set form id to status field.
// Set form id to status field.
if (isset($form['status']['widget']) && isset($form['status']['widget']['value'])) {
if (isset($form['status']['widget']) && isset($form['status']['widget']['value'])) {
$form['status']['widget']['value']['#attributes']['form'] = $form['#id'];
$form['status']['widget']['value']['#attributes']['form'] = $form['#id'];
}
}
if (isset($form['status']['#group'])) {
 
// Only move status to status group if it is a checkbox.
 
$widget_type = $form['status']['widget']['#type'] ?? FALSE;
 
if ($widget_type === 'checkbox' && isset($form['status']['#group'])) {
$form['status']['#group'] = 'status';
$form['status']['#group'] = 'status';
}
}
// Helper item to move focus to sticky header.
}
$form['gin_move_focus_to_sticky_bar'] = [
'#markup' => '<a href="#" class="visually-hidden" role="button" gin-move-focus-to-sticky-bar>Moves focus to sticky header actions</a>',
// Helper item to move focus to sticky header.
'#weight' => 999,
$form['gin_move_focus_to_sticky_bar'] = [
];
'#markup' => '<a href="#" class="visually-hidden" role="button" gin-move-focus-to-sticky-bar>Moves focus to sticky header actions</a>',
 
'#weight' => 999,
 
];
// Attach library.
// Attach library.
$form['#attached']['library'][] = 'gin/more_actions';
$form['#attached']['library'][] = 'gin/more_actions';
$form['#after_build'][] = 'gin_form_after_build';
$form['#after_build'][] = 'gin_form_after_build';
}
}
}
// Are we on an edit form?
// Remaining changes only apply to content forms.
if (!$this->isContentForm($form, $form_state, $form_id)) {
if (!$is_content_form) {
return;
return;
}
}
Loading