Skip to content
Snippets Groups Projects
Unverified Commit bb439263 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3461309 by annmarysruthy, charlliequadros, sivaji_ganesh_jojodae,...

Issue #3461309 by annmarysruthy, charlliequadros, sivaji_ganesh_jojodae, smustgrave, mstrelan: Refactor FormTestClickedButtonForm::buildForm

(cherry picked from commit 8c33fb4f)
parent f4950b18
Branches
No related tags found
4 merge requests!12024Fix: DocBlock comment for return value of Drupal\Core\Database\Connection::transactionManager(),!11974Draft: Issue #3495165 by catch, joeyroth, berdir, texas-bronius: Better warning...,!11934Issue #3520997: DefaultLazyPluginCollection unnecessarily instantiates plugins when sorting collection,!11887Issue #3520065: The migrate Row class API is incomplete
Pipeline #473762 passed
Pipeline: drupal

#473764

    ...@@ -35,32 +35,28 @@ public function buildForm(array $form, FormStateInterface $form_state, $first = ...@@ -35,32 +35,28 @@ public function buildForm(array $form, FormStateInterface $form_state, $first =
    '#type' => 'textfield', '#type' => 'textfield',
    ]; ];
    // Get button configurations, filter out NULL values.
    $args = array_filter([$first, $second, $third]);
    // Define button types for each argument.
    $button_types = [
    'submit',
    'image_button',
    'button',
    ];
    // Loop through each path argument, adding buttons based on the information // Loop through each path argument, adding buttons based on the information
    // in the argument. For example, if the path is // in the argument. For example, if the path is
    // form-test/clicked-button/s/i/rb, then 3 buttons are added: a 'submit', an // form-test/clicked-button/s/i/rb, then 3 buttons are added: a 'submit', an
    // 'image_button', and a 'button' with #access=FALSE. This enables form.test // 'image_button', and a 'button' with #access=FALSE. This enables form.test
    // to test a variety of combinations. // to test a variety of combinations.
    $i = 0; foreach ($args as $index => $arg) {
    $args = [$first, $second, $third]; // Get the button type based on the index of the argument.
    foreach ($args as $arg) { $type = $button_types[$index] ?? NULL;
    $name = 'button' . ++$i; $name = 'button' . ($index + 1);
    // 's', 'b', or 'i' in the argument define the button type wanted.
    if (!is_string($arg)) { if ($type) {
    $type = NULL; // Define the button.
    }
    elseif (str_contains($arg, 's')) {
    $type = 'submit';
    }
    elseif (str_contains($arg, 'b')) {
    $type = 'button';
    }
    elseif (str_contains($arg, 'i')) {
    $type = 'image_button';
    }
    else {
    $type = NULL;
    }
    if (isset($type)) {
    $form[$name] = [ $form[$name] = [
    '#type' => $type, '#type' => $type,
    '#name' => $name, '#name' => $name,
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment