You are here

class WebformDevelEntitySchemaForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_devel/src/Form/WebformDevelEntitySchemaForm.php \Drupal\webform_devel\Form\WebformDevelEntitySchemaForm

Get webform schema.

Hierarchy

Expanded class hierarchy of WebformDevelEntitySchemaForm

File

modules/webform_devel/src/Form/WebformDevelEntitySchemaForm.php, line 15

Namespace

Drupal\webform_devel\Form
View source
class WebformDevelEntitySchemaForm extends EntityForm {
  use WebformEntityAjaxFormTrait;

  /**
   * The webform devel scheme service.
   *
   * @var \Drupal\webform_devel\WebformDevelSchemaInterface
   */
  protected $scheme;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    $instance = parent::create($container);
    $instance->scheme = $container
      ->get('webform_devel.schema');
    return $instance;
  }

  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $webform_ui_exists = $this->moduleHandler
      ->moduleExists('webform_ui');

    /** @var \Drupal\webform\WebformInterface $webform */
    $webform = $this
      ->getEntity();

    // Header.
    $header = $this->scheme
      ->getColumns();
    if ($webform_ui_exists) {
      $header['operations'] = $this
        ->t('Operations');
    }

    // Rows.
    $rows = [];
    $elements = $this->scheme
      ->getElements($webform);
    foreach ($elements as $element_key => $element) {
      $rows[$element_key] = [];
      foreach ($element as $key => $value) {
        if ($key === 'options_value' || $key === 'options_text') {
          $value = implode('; ', array_slice($value, 0, 12)) . (count($value) > 12 ? '; …' : '');
        }
        $rows[$element_key][$key] = [
          '#markup' => $value,
        ];
      }
      if ($element['datatype'] === 'Composite') {
        $rows[$element_key]['#attributes']['class'][] = 'webform-devel-schema-composite';
      }
      if ($webform_ui_exists) {

        // Only add 'Edit' link to main element and not composite sub-elements.
        if (strpos($element_key, '.') === FALSE && $webform
          ->getElement($element_key)) {
          $element_url = new Url('entity.webform_ui.element.edit_form', [
            'webform' => $webform
              ->id(),
            'key' => $element_key,
          ], [
            'query' => [
              'destination' => Url::fromRoute('<current>')
                ->toString(),
            ],
          ]);
          $rows[$element_key]['name'] = [
            '#type' => 'link',
            '#title' => $element_key,
            '#url' => $element_url,
            '#attributes' => WebformDialogHelper::getModalDialogAttributes(),
          ];
          $rows[$element_key]['operations'] = [
            '#type' => 'link',
            '#title' => $this
              ->t('Edit'),
            '#url' => $element_url,
            '#attributes' => WebformDialogHelper::getModalDialogAttributes(WebformDialogHelper::DIALOG_NORMAL, [
              'button',
              'button--small',
            ]),
          ];
        }
        else {
          $rows[$element_key]['operations'] = [
            '#markup' => '',
          ];
        }

        // Add webform key used by Ajax callback.
        $rows[$element_key]['#attributes']['data-webform-key'] = explode('.', $element_key)[0];
      }
    }

    // Table.
    $form['schema'] = [
      '#type' => 'table',
      '#header' => $header,
      '#attributes' => [
        'class' => [
          'webform-devel-schema-table',
        ],
      ],
    ] + $rows;
    WebformDialogHelper::attachLibraries($form);
    $form['#attached']['library'][] = 'webform_devel/webform_devel';
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  protected function actionsElement(array $form, FormStateInterface $form_state) {
    $actions = parent::actionsElement($form, $form_state);
    unset($actions['delete']);
    $actions['submit']['#value'] = $this
      ->t('Export');
    $actions['reset']['#attributes']['style'] = 'display: none';
    return $actions;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_state
      ->setRedirect('webform_devel.schema.export', [
      'webform' => $this
        ->getEntity()
        ->id(),
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
EntityForm::$entity protected property The entity being used by this form. 11
EntityForm::$entityTypeManager protected property The entity type manager. 3
EntityForm::$moduleHandler protected property The module handler service.
EntityForm::$operation protected property The name of the current operation.
EntityForm::afterBuild public function Form element #after_build callback: Updates the entity with submitted data.
EntityForm::buildEntity public function Builds an updated entity object based upon the submitted form values. Overrides EntityFormInterface::buildEntity 3
EntityForm::copyFormValuesToEntity protected function Copies top-level form values to entity properties. 9
EntityForm::getBaseFormId public function Returns a string identifying the base form. Overrides BaseFormIdInterface::getBaseFormId 6
EntityForm::getEntity public function Gets the form entity. Overrides EntityFormInterface::getEntity
EntityForm::getEntityFromRouteMatch public function Determines which entity will be used by this form from a RouteMatch object. Overrides EntityFormInterface::getEntityFromRouteMatch 3
EntityForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId 12
EntityForm::getOperation public function Gets the operation identifying the form. Overrides EntityFormInterface::getOperation
EntityForm::init protected function Initialize the form state and the entity before the first form build. 3
EntityForm::prepareEntity protected function Prepares the entity object before the form is built first. 3
EntityForm::prepareInvokeAll protected function Invokes the specified prepare hook variant.
EntityForm::processForm public function Process callback: assigns weights and hides extra fields.
EntityForm::save public function Form submission handler for the 'save' action. Overrides EntityFormInterface::save 47
EntityForm::setEntity public function Sets the form entity. Overrides EntityFormInterface::setEntity
EntityForm::setEntityTypeManager public function Sets the entity type manager for this form. Overrides EntityFormInterface::setEntityTypeManager
EntityForm::setModuleHandler public function Sets the module handler for this form. Overrides EntityFormInterface::setModuleHandler
EntityForm::setOperation public function Sets the operation for this form. Overrides EntityFormInterface::setOperation
FormBase::$configFactory protected property The config factory. 3
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 3
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route.
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 72
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
WebformAjaxFormTrait::announce protected function Queue announcement with Ajax response.
WebformAjaxFormTrait::buildAjaxForm protected function Add Ajax support to a form.
WebformAjaxFormTrait::createAjaxResponse protected function Create an AjaxResponse or WebformAjaxResponse object.
WebformAjaxFormTrait::getAnnouncements protected function Get announcements.
WebformAjaxFormTrait::getFormStateRedirectUrl protected function Get redirect URL from the form's state.
WebformAjaxFormTrait::getWrapperId protected function Get the form's Ajax wrapper id. 1
WebformAjaxFormTrait::isCallableAjaxCallback protected function Determine if Ajax callback is callable.
WebformAjaxFormTrait::isDialog protected function Is the current request for an Ajax modal/dialog.
WebformAjaxFormTrait::isOffCanvasDialog protected function Is the current request for an off canvas dialog.
WebformAjaxFormTrait::missingAjaxCallback protected function Handle missing Ajax callback.
WebformAjaxFormTrait::noSubmit public function Empty submit callback used to only have the submit button to use an #ajax submit callback. 1
WebformAjaxFormTrait::resetAnnouncements protected function Reset announcements.
WebformAjaxFormTrait::setAnnouncements protected function Set announcements.
WebformAjaxFormTrait::submitAjaxForm public function Submit form #ajax callback. 1
WebformAjaxFormTrait::validateAjaxForm public function Validate form #ajax callback. 1
WebformDevelEntitySchemaForm::$scheme protected property The webform devel scheme service.
WebformDevelEntitySchemaForm::actionsElement protected function Returns the action form element for the current entity form. Overrides EntityForm::actionsElement
WebformDevelEntitySchemaForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
WebformDevelEntitySchemaForm::form public function Gets the actual form array to be built. Overrides EntityForm::form
WebformDevelEntitySchemaForm::submitForm public function This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state… Overrides EntityForm::submitForm
WebformEntityAjaxFormTrait::actions protected function
WebformEntityAjaxFormTrait::buildForm public function 1
WebformEntityAjaxFormTrait::cancelAjaxForm public function Cancel form #ajax callback. Overrides WebformAjaxFormTrait::cancelAjaxForm
WebformEntityAjaxFormTrait::getDefaultAjaxSettings protected function Get default ajax callback settings. Overrides WebformAjaxFormTrait::getDefaultAjaxSettings
WebformEntityAjaxFormTrait::isAjax protected function Returns if webform is using Ajax. Overrides WebformAjaxFormTrait::isAjax
WebformEntityAjaxFormTrait::isDialogDisabled protected function Determine if dialogs are disabled.
WebformEntityAjaxFormTrait::replaceForm protected function Replace form via an Ajax response. Overrides WebformAjaxFormTrait::replaceForm