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


PHP ContentEntityForm::submitForm方法代码示例

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


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

示例1: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     // The subscriptions field has properties which are set to NULL by ordinary
     // saving, which is wrong. The Subscriber::(un)subscribe() methods save the
     // values correctly. For each newsletter ID we check if it exists in
     // current subscriptions and new subscriptions respectively.
     $current_subscriptions = $this->entity->getSubscribedNewsletterIds();
     $subscription_values = $form_state->getValue('subscriptions');
     $new_subscriptions = array();
     foreach ($subscription_values as $subscription_value) {
         array_push($new_subscriptions, $subscription_value['target_id']);
     }
     foreach (array_keys(simplenews_newsletter_get_visible()) as $newsletter) {
         if (in_array($newsletter, $current_subscriptions) && !in_array($newsletter, $new_subscriptions)) {
             $this->entity->unsubscribe($newsletter);
         } elseif (!in_array($newsletter, $current_subscriptions) && in_array($newsletter, $new_subscriptions)) {
             $this->entity->subscribe($newsletter);
         }
     }
     $form_state->setRedirect('view.simplenews_subscribers.page_1');
     if ($this->entity->isNew()) {
         drupal_set_message($this->t('Subscriber %label has been added.', array('%label' => $this->entity->label())));
     } else {
         drupal_set_message($this->t('Subscriber %label has been updated.', array('%label' => $this->entity->label())));
     }
 }
开发者ID:aritnath1990,项目名称:simplenewslatest,代码行数:30,代码来源:SubscriberForm.php

示例2: submitForm

 /**
  * {@inheritdoc}
  *
  * Always create a new revision
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Build the node object from the submitted values.
     parent::submitForm($form, $form_state);
     // Set new revision if needed
     if ($this->entity->id()) {
         $this->setNewRevision($form_state);
     }
 }
开发者ID:shrimala,项目名称:ahsweb,代码行数:14,代码来源:DiscussionForm.php

示例3: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     /** @var \Drupal\user\Entity\User $assignee */
     $assignee = User::load($form_state->getValue('tuid'));
     /** @var \Drupal\tmgmt_local\LocalTaskInterface $task */
     $task = $this->getEntity();
     $task->assign($assignee);
     $task->save();
     drupal_set_message(t('Assigned @label to user @assignee_name.', array('@label' => $task->label(), '@assignee_name' => $assignee->getAccountName())));
     $view = Views::getView('tmgmt_local_task_overview');
     $view->initDisplay();
     $form_state->setRedirect($view->getUrl()->getRouteName());
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:17,代码来源:LocalTaskAssignForm.php

示例4: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     $order = $this->entity;
     $original = clone $order;
     // Build list of changes to be applied.
     $panes = _uc_order_pane_list();
     foreach ($panes as $pane) {
         if (in_array('edit', $pane['show'])) {
             $pane['callback']('edit-process', $order, $form, $form_state);
         }
     }
     $log = array();
     foreach (array_keys($order->getFieldDefinitions()) as $key) {
         if ($original->{$key}->value !== $order->{$key}->value) {
             if (!is_array($order->{$key}->value)) {
                 $log[$key] = array('old' => $original->{$key}->value, 'new' => $order->{$key}->value);
             }
         }
     }
     if (\Drupal::moduleHandler()->moduleExists('uc_stock')) {
         $qtys = array();
         foreach ($order->products as $product) {
             $qtys[$product->order_product_id] = $product->qty;
         }
     }
     if (is_array($form_state->getValue('products'))) {
         foreach ($form_state->getValue('products') as $product) {
             if (!isset($product['remove']) && intval($product['qty']) > 0) {
                 foreach (array('qty', 'title', 'model', 'weight', 'weight_units', 'cost', 'price') as $field) {
                     $order->products[$product['order_product_id']]->{$field} = $product[$field];
                 }
                 if (\Drupal::moduleHandler()->moduleExists('uc_stock')) {
                     $product = (object) $product;
                     $temp = $product->qty;
                     $product->qty = $product->qty - $qtys[$product->order_product_id];
                     uc_stock_adjust_product_stock($product, 0, $order);
                     $product->qty = $temp;
                 }
             } else {
                 $log['remove_' . $product['nid']] = $product['title'] . ' removed from order.';
             }
         }
     }
     // Load line items again, since some may have been updated by the form.
     $order->line_items = $order->getLineItems();
     $order->logChanges($log);
     $order->save();
     drupal_set_message(t('Order changes saved.'));
 }
开发者ID:pedrocones,项目名称:hydrotools,代码行数:53,代码来源:OrderForm.php

示例5: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Build the media object from the submitted values.
     parent::submitForm($form, $form_state);
     $media = $this->entity;
     // Save as a new revision if requested to do so.
     if (!$form_state->isValueEmpty('revision') && $form_state->getValue('revision') != FALSE) {
         $media->setNewRevision();
         // If a new revision is created, save the current user as revision author.
         $media->set('revision_timestamp', REQUEST_TIME);
         $media->set('revision_uid', $this->currentUser()->id());
     } else {
         $media->setNewRevision(FALSE);
     }
 }
开发者ID:sedurzu,项目名称:ildeposito8,代码行数:18,代码来源:MediaForm.php

示例6: submitForm

 /**
  * Overrides \Drupal\Core\Entity\EntityFormController::submit().
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Build the block object from the submitted values.
     parent::submitForm($form, $form_state);
     $field_collection_item = $this->entity;
     // TODO: Create new revision every edit?  Might be better to make it an
     // option.  In either case, it doesn't work as is.  The default
     // revision of the host isn't getting updated to point to the new
     // field collection item revision.
     // $field_collection_item->setNewRevision();
     if (\Drupal::routeMatch()->getRouteName() == 'field_collection_item.add_page') {
         $host = entity_load(\Drupal::routeMatch()->getParameter('host_type'), \Drupal::routeMatch()->getParameter('host_id'));
     } else {
         $host = $field_collection_item->getHost();
     }
     $form_state->setRedirect($host->urlInfo()->getRouteName(), $host->urlInfo()->getRouteParameters());
 }
开发者ID:vanilla-bear,项目名称:drupal8,代码行数:20,代码来源:FieldCollectionItemForm.php

示例7: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     $user = $this->getEntity($form_state);
     // If there's a session set to the users id, remove the password reset tag
     // since a new password was saved.
     if (isset($_SESSION['pass_reset_' . $user->id()])) {
         unset($_SESSION['pass_reset_' . $user->id()]);
     }
 }
开发者ID:dmyerson,项目名称:d8ecs,代码行数:13,代码来源:AccountForm.php

示例8: submitForm

 /**
  * {@inheritdoc}
  *
  * Always create a new revision
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Build the node object from the submitted values.
     parent::submitForm($form, $form_state);
     // If not a new entity, get the original
     $original = NULL;
     if ($this->entity->id()) {
         $storage = \Drupal::entityManager()->getStorage('node');
         $original = $storage->loadUnchanged($this->entity->id());
     }
     $this->addUserAsParticipant($original);
     // Set new revision if needed
     if ($this->entity->id()) {
         $this->considerNewRevision($form_state, $original);
     }
 }
开发者ID:shrimala,项目名称:ahsweb,代码行数:21,代码来源:DiscussionForm.php

示例9: submitForm

 /**
  * {@inheritdoc}
  *
  * Updates the node object by processing the submitted values.
  *
  * This function can be called by a "Next" button of a wizard to update the
  * form state's entity with the current step's values before proceeding to the
  * next step.
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Build the node object from the submitted values.
     parent::submitForm($form, $form_state);
     $node = $this->entity;
     // Save as a new revision if requested to do so.
     if (!$form_state->isValueEmpty('revision') && $form_state->getValue('revision') != FALSE) {
         $node->setNewRevision();
         // If a new revision is created, save the current user as revision author.
         $node->setRevisionCreationTime(REQUEST_TIME);
         $node->setRevisionAuthorId(\Drupal::currentUser()->id());
     } else {
         $node->setNewRevision(FALSE);
     }
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:24,代码来源:NodeForm.php

示例10: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     /** @var \Drupal\comment\CommentInterface $comment */
     $comment = $this->entity;
     // If the comment was posted by a registered user, assign the author's ID.
     // @todo Too fragile. Should be prepared and stored in comment_form()
     // already.
     $author_name = $comment->getAuthorName();
     if (!$comment->is_anonymous && !empty($author_name) && ($account = user_load_by_name($author_name))) {
         $comment->setOwner($account);
     }
     // If the comment was posted by an anonymous user and no author name was
     // required, use "Anonymous" by default.
     if ($comment->is_anonymous && (!isset($author_name) || $author_name === '')) {
         $comment->setAuthorName($this->config('user.settings')->get('anonymous'));
     }
     // Validate the comment's subject. If not specified, extract from comment
     // body.
     if (trim($comment->getSubject()) == '') {
         // The body may be in any format, so:
         // 1) Filter it into HTML
         // 2) Strip out all HTML tags
         // 3) Convert entities back to plain-text.
         $comment_text = $comment->comment_body->processed;
         $comment->setSubject(Unicode::truncate(trim(String::decodeEntities(strip_tags($comment_text))), 29, TRUE));
         // Edge cases where the comment body is populated only by HTML tags will
         // require a default subject.
         if ($comment->getSubject() == '') {
             $comment->setSubject($this->t('(No subject)'));
         }
     }
     return $comment;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:37,代码来源:CommentForm.php

示例11: submitConfigurationForm

 /**
  * {@inheritdoc}
  */
 public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     // Remove button and internal Form API values from submitted values.
     parent::submitForm($form, $form_state);
     $this->save($form, $form_state);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:9,代码来源:MenuLinkContentForm.php

示例12: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     /** @var OrderInterface $order */
     $order = $this->entity;
     $original = clone $order;
     // Build list of changes to be applied.
     $panes = $this->orderPaneManager->getPanes();
     foreach ($panes as $pane) {
         if ($pane instanceof EditableOrderPanePluginInterface) {
             $pane->submitForm($order, $form, $form_state);
         }
     }
     $log = array();
     foreach (array_keys($order->getFieldDefinitions()) as $key) {
         if ($original->{$key}->value !== $order->{$key}->value) {
             if (!is_array($order->{$key}->value)) {
                 $log[$key] = array('old' => $original->{$key}->value, 'new' => $order->{$key}->value);
             }
         }
     }
     // Load line items again, since some may have been updated by the form.
     $order->line_items = $order->getLineItems();
     $order->logChanges($log);
     $order->save();
     drupal_set_message($this->t('Order changes saved.'));
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:30,代码来源:OrderForm.php

示例13: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Subclasses try to load an existing subscriber in different ways in
     // buildForm. For anonymous user the email is unknown in buildForm, but here
     // we can try again to load an existing subscriber.
     $mail = $form_state->getValue(array('mail', 0, 'value'));
     if ($this->entity->isNew() && isset($mail) && ($subscriber = simplenews_subscriber_load_by_mail($mail))) {
         $this->setEntity($subscriber);
     }
     parent::submitForm($form, $form_state);
 }
开发者ID:aritnath1990,项目名称:simplenewslatest,代码行数:14,代码来源:SubscriptionsFormBase.php

示例14: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     $this->plugin->submitConfigurationForm($form, $form_state);
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:8,代码来源:RuleComponentForm.php

示例15: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     $line_item_type_storage = $this->entityManager->getStorage('commerce_line_item_type');
     /** @var \Drupal\commerce_order\Entity\LineItemInterface $line_item */
     $line_item = $this->entity;
     /** @var \Drupal\commerce\PurchasableEntityInterface $purchased_entity */
     $purchased_entity = $line_item->getPurchasedEntity();
     /** @var \Drupal\commerce_order\Entity\LineItemTypeInterface $line_item_type */
     $line_item_type = $line_item_type_storage->load($line_item->bundle());
     $store = $this->selectStore($purchased_entity);
     $cart = $this->cartProvider->getCart($line_item_type->getOrderTypeId(), $store);
     if (!$cart) {
         $cart = $this->cartProvider->createCart('default', $store);
     }
     $this->cartManager->addLineItem($cart, $line_item, $form_state->get(['settings', 'combine']));
     drupal_set_message(t('@entity added to @cart-link.', ['@entity' => $purchased_entity->label(), '@cart-link' => Link::createFromRoute('your cart', 'commerce_cart.page')->toString()]));
 }
开发者ID:alexburrows,项目名称:cream-2.x,代码行数:21,代码来源:AddToCartForm.php


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