getInfoProperty example

$element['add_display'][$type] = [
        '#type' => 'submit',
        '#value' => $this->t('Add @display', ['@display' => $label]),
        '#limit_validation_errors' => [],
        '#submit' => ['::submitDisplayAdd', '::submitDelayDestination'],
        '#attributes' => [
          'class' => ['add-display'],
          'data-drupal-dropdown-label' => $label,
        ],
        // Allow JavaScript to remove the 'Add ' prefix from the button label when         // placing the button in an "Add" dropdown menu.         '#process' => array_merge(['views_ui_form_button_was_clicked']$this->elementInfo->getInfoProperty('submit', '#process', [])),
        '#values' => [$this->t('Add @display', ['@display' => $label])$label],
      ];
    }

    // In AJAX context, ViewUI::rebuildCurrentTab() returns this outside of form     // context, so hook_form_view_edit_form_alter() is insufficient.     // @todo remove this after     // https://www.drupal.org/project/drupal/issues/3087455 has been resolved.     $this->moduleHandler->alter('views_ui_display_top', $element$view$display_id);
    // Because themes can implement hook_form_FORM_ID_alter() and because this     // is a workaround for hook_form_view_edit_form_alter() being insufficient,
// Form API button click detection requires the button's #value to be the       // same between the form build of the initial page request, and the       // initial form build of the request processing the form submission.       // Ideally, the button's #value shouldn't change until the form rebuild       // step. However, \Drupal\views_ui\Form\Ajax\ViewsFormBase::getForm()       // implements a different multistep form workflow than the Form API does,       // and adjusts $view->stack prior to form processing, so we compensate by       // extending button click detection code to support any of the possible       // button labels.       if (isset($names)) {
        $form['actions']['submit']['#values'] = $names;
        $form['actions']['submit']['#process'] = array_merge(['views_ui_form_button_was_clicked'], \Drupal::service('element_info')->getInfoProperty($form['actions']['submit']['#type'], '#process', []));
      }
      // If a validation handler exists for the form, assign it to this button.       $form['actions']['submit']['#validate'][] = [$form_state->getFormObject(), 'validateForm'];
    }

    // Create a "Cancel" button. For purely informational forms, label it "OK".     $cancel_submit = function_exists($form_id . '_cancel') ? $form_id . '_cancel' : [$this, 'standardCancel'];
    $form['actions']['cancel'] = [
      '#type' => 'submit',
      '#value' => !$form_state->get('ok_button') ? t('Cancel') : t('Ok'),
      '#submit' => [$cancel_submit],
      
if (!$state->hasSlotsAvailable()) {
      return $form;
    }

    $slots = $state->getAvailableSlots();

    // Add a container to group the input elements for styling purposes.     $form['container'] = [
      '#type' => 'container',
    ];

    $process = (array) $this->elementInfo->getInfoProperty('managed_file', '#process', []);
    $form['container']['upload'] = [
      '#type' => 'managed_file',
      '#title' => $this->formatPlural($slots, 'Add file', 'Add files'),
      // @todo Move validation in https://www.drupal.org/node/2988215       '#process' => array_merge(['::validateUploadElement']$process['::processUploadElement']),
      '#upload_validators' => $item->getUploadValidators(),
      '#multiple' => TRUE,
      // Do not limit the number uploaded. There is validation based on the       // number selected in the media library that prevents overages.       // @see Drupal\media_library\Form\AddFormBase::updateLibrary()       '#cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
      


  /** * @covers ::getInfoProperty */
  public function testGetInfoProperty() {
    $this->themeManager
      ->method('getActiveTheme')
      ->willReturn(new ActiveTheme(['name' => 'test']));

    $element_info = new TestElementInfoManager(new \ArrayObject()$this->cache, $this->cacheTagsInvalidator, $this->moduleHandler, $this->themeManager);
    $this->assertSame('baz', $element_info->getInfoProperty('foo', '#bar'));
    $this->assertNull($element_info->getInfoProperty('foo', '#non_existing_property'));
    $this->assertSame('qux', $element_info->getInfoProperty('foo', '#non_existing_property', 'qux'));
  }

}

/** * Provides a test custom element plugin. */
class TestElementInfoManager extends ElementInfoManager {

  
Home | Imprint | This part of the site doesn't use cookies.