当前位置: 首页>>代码示例>>PHP>>正文


PHP FormStateInterface::getFormObject方法代码示例

本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::getFormObject方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::getFormObject方法的具体用法?PHP FormStateInterface::getFormObject怎么用?PHP FormStateInterface::getFormObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Form\FormStateInterface的用法示例。


在下文中一共展示了FormStateInterface::getFormObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_form_entity

 /**
  * @param FormStateInterface $form_state
  * @return object | bool
  */
 public static function get_form_entity($form_state)
 {
     if (!is_null($form_state->getFormObject()) && method_exists($form_state->getFormObject(), 'getEntity')) {
         $entity = $form_state->getFormObject()->getEntity();
         return $entity;
     }
     return FALSE;
 }
开发者ID:samuelmc,项目名称:custom_sitemap,代码行数:12,代码来源:Customsitemap.php

示例2: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     /* @var $instance \Drupal\mailchimp_lists\Plugin\Field\FieldType\MailchimpListsSubscription */
     $instance = $items[0];
     $subscribe_default = $instance->getSubscribe();
     $email = NULL;
     if (!empty($instance->getEntity())) {
         $email = mailchimp_lists_load_email($instance, $instance->getEntity(), FALSE);
         if ($email) {
             $subscribe_default = mailchimp_is_subscribed($instance->getFieldDefinition()->getSetting('mc_list_id'), $email);
         }
     }
     $element += array('#title' => SafeMarkup::checkPlain($element['#title']), '#type' => 'fieldset');
     $element['subscribe'] = array('#title' => t('Subscribe'), '#type' => 'checkbox', '#default_value' => $subscribe_default ? TRUE : $this->fieldDefinition->isRequired(), '#required' => $this->fieldDefinition->isRequired(), '#disabled' => $this->fieldDefinition->isRequired());
     $form_id = $form_state->getFormObject()->getFormId();
     if ($this->fieldDefinition->getSetting('show_interest_groups') || $form_id == 'field_ui_field_edit_form') {
         $mc_list = mailchimp_get_list($instance->getFieldDefinition()->getSetting('mc_list_id'));
         $element['interest_groups'] = array('#type' => 'fieldset', '#title' => SafeMarkup::checkPlain($instance->getFieldDefinition()->getSetting('interest_groups_title')), '#weight' => 100, '#states' => array('invisible' => array(':input[name="' . $instance->getFieldDefinition()->getName() . '[0][value][subscribe]"]' => array('checked' => FALSE))));
         if ($form_id == 'field_ui_field_edit_form') {
             $element['interest_groups']['#states']['invisible'] = array(':input[name="field[settings][show_interest_groups]"]' => array('checked' => FALSE));
         }
         $groups_default = $instance->getInterestGroups();
         if ($groups_default == NULL) {
             $groups_default = array();
         }
         if ($mc_list['stats']['group_count']) {
             $element['interest_groups'] += mailchimp_interest_groups_form_elements($mc_list, $groups_default, $email);
         }
     }
     return array('value' => $element);
 }
开发者ID:rafavergara,项目名称:ddv8,代码行数:34,代码来源:MailchimpListsSelectWidget.php

示例3: buildConfigurationForm

 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, FormStateInterface $form_state)
 {
     $form_object = $form_state->getFormObject();
     $form['animal_type'] = ['#type' => 'select', '#title' => $this->t('Animal type'), '#options' => ['vertebrates' => $this->t('Vertebrates (with backbone)'), 'invertebrates' => $this->t('Invertebrates (without backbone)')], '#default_value' => $this->getConfigurationValue('animal_type'), '#required' => TRUE, '#ajax' => ['callback' => [$form_object, 'updateTypeSettings'], 'effect' => 'fade']];
     if ($this->getConfigurationValue('animal_type') === 'vertebrates') {
         $form['allowed_vertebrates'] = ['#type' => 'checkboxes', '#title' => $this->t('Limit allowed vertebrates'), '#options' => ['amphibians' => $this->t('Amphibians'), 'birds' => $this->t('Birds'), 'fish' => $this->t('Fish'), 'mammals' => $this->t('Mammals'), 'reptiles' => $this->t('Reptiles')], '#default_value' => $this->getConfigurationValue('allowed_vertebrates', [])];
     }
     return $form;
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:12,代码来源:Animal.php

示例4: addFeedbackOptionsSubmit

 /**
  * Submit handler for feedback options.
  */
 public static function addFeedbackOptionsSubmit(&$form, FormStateInterface &$form_state)
 {
     $forms = FormController::getProtectedForms();
     $mollom_form = Form::load($forms['delete'][$form_state->getFormObject()->getFormId()])->initialize();
     $entity_type = $mollom_form['entity'];
     if (!empty($entity_type)) {
         $id = $form_state->getFormObject()->getEntity()->id();
     } else {
         $id = $form_state->getValue($mollom_form['mapping']['post_id']);
     }
     $feedback = $form_state->getValue(array('mollom', 'feedback'));
     if (!empty($feedback)) {
         if (self::sendFeedback($entity_type, $id, $feedback, 'moderate', 'mollom_data_delete_form_submit')) {
             drupal_set_message(t('The content was successfully reported as inappropriate.'));
         }
     }
     // Remove Mollom session data.
     ResponseDataStorage::delete($entity_type, $id);
 }
开发者ID:isramv,项目名称:camp-gdl,代码行数:22,代码来源:FeedbackManager.php

示例5: enforceRevisionsBundleFormAlter

 /**
  * {@inheritdoc}
  */
 public function enforceRevisionsBundleFormAlter(array &$form, FormStateInterface $form_state, $form_id)
 {
     /* @var \Drupal\node\Entity\NodeType $entity */
     $entity = $form_state->getFormObject()->getEntity();
     if ($entity->getThirdPartySetting('content_moderation', 'enabled', FALSE)) {
         // Force the revision checkbox on.
         $form['workflow']['options']['#default_value']['revision'] = 'revision';
         $form['workflow']['options']['revision']['#disabled'] = TRUE;
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:13,代码来源:NodeModerationHandler.php

示例6: buildForm

 /**
  * {@inheritdoc}
  *
  * @todo Change this because $component could be component type or component id
  *       Would make sense to make our own ParamConverterInterface's so component is loaded at this point?
  */
 public function buildForm(array $form, FormStateInterface $form_state, Node $node = NULL, $component = NULL)
 {
     // Load the component plugin.
     $form_state->getFormObject();
     if (empty($form['#component'])) {
         $component = $this->prepareComponent($node, $component);
     } else {
         $component = $form['#component'];
     }
     // Get the form from the component plugin.
     $form = $component->buildForm($form, $form_state, $node);
     return $form;
 }
开发者ID:edwardchan,项目名称:d8-drupalvm,代码行数:19,代码来源:WebformComponentFormBase.php

示例7: entityFormEntityBuild

 /**
  * {@inheritdoc}
  */
 public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state)
 {
     if ($form_state->hasValue('content_translation')) {
         $form_object = $form_state->getFormObject();
         $translation =& $form_state->getValue('content_translation');
         $translation['status'] = $form_object->getEntity()->isPublished();
         // $form['content_translation']['name'] is the equivalent field
         // for translation author uid.
         $account = $entity->uid->entity;
         $translation['name'] = $account ? $account->getUsername() : '';
         $translation['created'] = format_date($entity->created->value, 'custom', 'Y-m-d H:i:s O');
     }
     parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:17,代码来源:NodeTranslationHandler.php

示例8: submitForm

  /**
   * Saves Schema.org mappings in \Drupal\node\NodeTypeForm.
   */
  public static function submitForm(array &$form, FormStateInterface $form_state) {
    if ($form_state->hasValue('types')) {
      $entity_type = $form_state->getFormObject()->getEntity();
      $mapping = rdf_get_mapping('node', $entity_type->id());
      if ($entity_type->isNew()) {
        $mapping = rdf_get_mapping('node', $form_state->getValue('types'));
      }

      if ($form_state->hasValue('types')) {
        $mapping->setBundleMapping(array('types' => array($form_state->getValue('types'))))
          ->save();
      }
    }
  }
开发者ID:eloiv,项目名称:botafoc.cat,代码行数:17,代码来源:ContentMappings.php

示例9: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     // Determine if this is an existing or a new entity.
     /** @var \Drupal\Core\Entity\ContentEntityFormInterface $form_object */
     $form_object = $form_state->getFormObject();
     /** @var \Drupal\Core\Entity\EntityInterface $entity */
     $entity = $form_object->getEntity();
     $is_new = empty($entity->id());
     $behaviour = $this->getSetting('behaviour');
     if ($behaviour == 'create' && $is_new || $behaviour == 'modified') {
         $element['set_date'] = ['#type' => 'item', '#value' => TRUE];
     }
     return $element;
 }
开发者ID:ec-europa,项目名称:joinup-dev,代码行数:17,代码来源:DateTimeCreateUpdateWidget.php

示例10: buildConfigurationForm

 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, FormStateInterface $form_state)
 {
     $options = [];
     foreach ($this->entityFieldManager->getFieldDefinitions('media', $form_state->getFormObject()->getEntity()->id()) as $field_name => $field) {
         if ($field->getType() == 'video_embed_field') {
             $options[$field_name] = $field->getLabel();
         }
     }
     if (empty($options)) {
         $form['summary']['#markup'] = $this->t('A video embed field will be created on this media bundle when you save this form. You can return to this configuration screen to alter the video field used for this bundle, or you can use the one provided.');
     }
     if (!empty($options)) {
         $form['source_field'] = ['#type' => 'select', '#required' => TRUE, '#title' => t('Source Video Field'), '#description' => t('The field on the media entity that contains the video URL.'), '#default_value' => empty($this->configuration['source_field']) ? VideoEmbedField::VIDEO_EMBED_FIELD_DEFAULT_NAME : $this->configuration['source_field'], '#options' => $options];
     }
     return $form;
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:19,代码来源:VideoEmbedField.php

示例11: fieldSettingsFormValidate

 /**
  * Form element validation handler; Invokes selection plugin's validation.
  *
  * @param array $form
  *   The form where the settings form is being included in.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The form state of the (entire) configuration form.
  */
 public static function fieldSettingsFormValidate(array $form, FormStateInterface $form_state)
 {
     $field = $form_state->getFormObject()->getEntity();
     $handler = \Drupal::service('plugin.manager.entity_reference_selection')->getSelectionHandler($field);
     $handler->validateConfigurationForm($form, $form_state);
 }
开发者ID:318io,项目名称:318-io,代码行数:14,代码来源:EntityReferenceItem.php

示例12: ajaxReviewForm

 /**
  * Ajax callback for the job item review form.
  */
 function ajaxReviewForm(array $form, FormStateInterface $form_state)
 {
     $key = array_slice($form_state->getTriggeringElement()['#array_parents'], 0, 2);
     $render_data = NestedArray::getValue($form, $key);
     tmgmt_write_request_messages($form_state->getFormObject()->getEntity()->getJob());
     return $render_data;
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:10,代码来源:JobItemForm.php

示例13: retrieveForm

 /**
  * {@inheritdoc}
  */
 public function retrieveForm($form_id, FormStateInterface &$form_state)
 {
     // Record the $form_id.
     $form_state->addBuildInfo('form_id', $form_id);
     // We save two copies of the incoming arguments: one for modules to use
     // when mapping form ids to constructor functions, and another to pass to
     // the constructor function itself.
     $build_info = $form_state->getBuildInfo();
     $args = $build_info['args'];
     $callback = [$form_state->getFormObject(), 'buildForm'];
     $form = array();
     // Assign a default CSS class name based on $form_id.
     // This happens here and not in self::prepareForm() in order to allow the
     // form constructor function to override or remove the default class.
     $form['#attributes']['class'][] = Html::getClass($form_id);
     // Same for the base form ID, if any.
     if (isset($build_info['base_form_id'])) {
         $form['#attributes']['class'][] = Html::getClass($build_info['base_form_id']);
     }
     // We need to pass $form_state by reference in order for forms to modify it,
     // since call_user_func_array() requires that referenced variables are
     // passed explicitly.
     $args = array_merge(array($form, &$form_state), $args);
     $form = call_user_func_array($callback, $args);
     // If the form returns some kind of response, deliver it.
     if ($form instanceof Response) {
         $this->sendResponse($form);
         exit;
     }
     $form['#form_id'] = $form_id;
     return $form;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:35,代码来源:FormBuilder.php

示例14: processActions

 /**
  * Process callback to alter action buttons.
  */
 public static function processActions($element, FormStateInterface $form_state, array &$form)
 {
     // We'll steal most of the button configuration from the default submit
     // button. However, NodeForm also hides that button for admins (as it adds
     // its own, too), so we have to restore it.
     $default_button = $form['actions']['submit'];
     $default_button['#access'] = TRUE;
     // Add a custom button for each transition we're allowing. The #dropbutton
     // property tells FAPI to cluster them all together into a single widget.
     $options = $element['#options'];
     $entity = $form_state->getFormObject()->getEntity();
     $translatable = !$entity->isNew() && $entity->isTranslatable();
     foreach ($options as $id => $label) {
         $button = ['#dropbutton' => 'save', '#moderation_state' => $id, '#weight' => -10];
         $button['#value'] = $translatable ? t('Save and @transition (this translation)', ['@transition' => $label]) : t('Save and @transition', ['@transition' => $label]);
         $form['actions']['moderation_state_' . $id] = $button + $default_button;
     }
     // Hide the default buttons, including the specialty ones added by
     // NodeForm.
     foreach (['publish', 'unpublish', 'submit'] as $key) {
         $form['actions'][$key]['#access'] = FALSE;
         unset($form['actions'][$key]['#dropbutton']);
     }
     // Setup a callback to translate the button selection back into field
     // widget, so that it will get saved properly.
     $form['#entity_builders']['update_moderation_state'] = [get_called_class(), 'updateStatus'];
     return $element;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:31,代码来源:ModerationStateWidget.php

示例15: entityFormDeleteTranslation

 /**
  * Form submission handler for ContentTranslationHandler::entityFormAlter().
  *
  * Takes care of content translation deletion.
  */
 function entityFormDeleteTranslation($form, FormStateInterface $form_state)
 {
     $form_object = $form_state->getFormObject();
     $entity = $form_object->getEntity();
     $entity_type_id = $entity->getEntityTypeId();
     $form_state->setRedirect('content_translation.translation_delete_' . $entity_type_id, array($entity_type_id => $entity->id(), 'language' => $form_object->getFormLangcode($form_state)));
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:12,代码来源:ContentTranslationHandler.php


注:本文中的Drupal\Core\Form\FormStateInterface::getFormObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。