當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。