php Drupal-Core-Entity-ContentEntityForm类(方法)实例源码

下面列出了php Drupal-Core-Entity-ContentEntityForm 类(方法)源码代码实例,从而了解它的用法。

作者:aritnath199    项目:simplenewslates   
/**
  * {@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())));
     }
 }

作者:davidsoloma    项目:drupalconsole.co   
/**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     if (!$this->pathValidator->isValid($form_state->getValue('path'))) {
         $form_state->setErrorByName('path', $this->t('The shortcut must correspond to a valid path on the site.'));
     }
     parent::validate($form, $form_state);
 }

作者:andrew    项目:andrewlne   
/**
  * {@inheritdoc}
  */
 protected function actions(array $form, FormStateInterface $form_state)
 {
     $actions = parent::actions($form, $form_state);
     $actions['submit']['#value'] = $this->t('Save task');
     $actions['submit']['#access'] = \Drupal::currentUser()->hasPermission('administer tmgmt') || \Drupal::currentUser()->hasPermission('administer translation tasks');
     return $actions;
 }

作者:bnchdrf    项目:foo_ba   
/**
  * Overrides \Drupal\Core\Entity\EntityFormController::submit().
  */
 public function submit(array $form, array &$form_state)
 {
     // Build the entity object from the submitted values.
     $entity = parent::submit($form, $form_state);
     $form_state['redirect_route']['route_name'] = 'foo_bar.list';
     return $entity;
 }

作者:anatalsce    项目:en-class   
/**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     if (!shortcut_valid_link($form_state['values']['path'])) {
         $form_state->setErrorByName('path', $this->t('The shortcut must correspond to a valid path on the site.'));
     }
     parent::validate($form, $form_state);
 }

作者:AshishNaik02    项目:iimisac-d   
/**
   * {@inheritdoc}
   */
  public function actions(array $form, FormStateInterface $form_state) {
    $actions = parent::actions($form, $form_state);

    if ($this->entity->isNew()) {
      $actions['submit']['#value'] = $this->t('Create Flagging');
    }
    else {
      $actions['submit']['#value'] = $this->t('Update Flagging');
    }

    // Customize the delete link.
    if (isset($actions['delete'])) {
      // @todo Why does the access call always fail?
      unset($actions['delete']['#access']);

      $actions['delete']['#title'] = $this->t('Delete Flagging');

      // Build the delete url from route. We need to build this manually
      // otherwise Drupal will try to build the flagging entity's delete-form
      // link. Since that route doesn't use the flagging ID, Drupal can't build
      // the link for us.
      $route_params = [
        'flag' => $this->entity->getFlagId(),
        'entity_id' => $this->entity->getFlaggableId(),
        'destination' => \Drupal::request()->get('destination'),
      ];
      $url = Url::fromRoute('flag.confirm_unflag', $route_params);

      $actions['delete']['#url'] = $url;
    }

    return $actions;
  }

作者:housineal    项目:drpl8_d   
/**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    /* @var \Drupal\commerce_order\Entity\Order $order */
    $order = $this->entity;
    $currentUser = $this->currentUser();

    $form['advanced'] = [
      '#type' => 'vertical_tabs',
      '#attributes' => ['class' => ['entity-meta']],
      '#weight' => 99,
    ];
    $form = parent::form($form, $form_state);

    $form['order_status'] = [
      '#type' => 'details',
      '#title' => t('Order status'),
      '#group' => 'advanced',
      '#attributes' => [
        'class' => ['order-form-order-status'],
      ],
      '#attached' => [
        'library' => ['commerce_order/drupal.commerce_order'],
      ],
      '#weight' => 90,
      '#optional' => TRUE,
    ];

    if (isset($form['status'])) {
      $form['status']['#group'] = 'order_status';
    }

    // Order authoring information for administrators.
    $form['author'] = [
      '#type' => 'details',
      '#title' => t('Authoring information'),
      '#group' => 'advanced',
      '#attributes' => [
        'class' => ['order-form-author'],
      ],
      '#attached' => [
        'library' => ['commerce_order/drupal.commerce_order'],
      ],
      '#weight' => 91,
      '#optional' => TRUE,
    ];

    if (isset($form['uid'])) {
      $form['uid']['#group'] = 'author';
    }

    if (isset($form['mail'])) {
      $form['mail']['#group'] = 'author';
    }

    if (isset($form['created'])) {
      $form['created']['#group'] = 'author';
    }

    return $form;
  }

作者:walleca    项目:drupalp   
/**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $reservation = $this->entity;
     $season_storage = $this->entityManager->getStorage('season');
     $season = $season_storage->load($reservation->bundle());
     $form['season'] = array('#type' => 'value', '#value' => $season->id());
     return parent::form($form, $form_state);
 }

作者:anatalsce    项目:en-class   
/**
  * {@inheritdoc}
  */
 protected function actions(array $form, FormStateInterface $form_state)
 {
     $actions = parent::actions($form, $form_state);
     $actions['submit']['#value'] = $this->entity->book['original_bid'] ? $this->t('Update book outline') : $this->t('Add to book outline');
     $actions['delete']['#value'] = $this->t('Remove from book outline');
     $actions['delete']['#access'] = $this->bookManager->checkNodeIsRemovable($this->entity);
     return $actions;
 }

作者:hugronapho    项目:corne   
/**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     /* @var $entity \Drupal\content_entity_example\Entity\Contact */
     $form = parent::buildForm($form, $form_state);
     $entity = $this->entity;
     $form['langcode'] = array('#title' => $this->t('Language'), '#type' => 'language_select', '#default_value' => $entity->getUntranslated()->language()->getId(), '#languages' => Language::STATE_ALL);
     return $form;
 }

作者:alnutil    项目:drunatr   
/**
  * {@inheritdoc}
  */
 protected function actions(array $form, array &$form_state)
 {
     $actions = parent::actions($form, $form_state);
     $actions['submit']['#value'] = $this->getConfirmText();
     unset($actions['delete']);
     // Prepare cancel link.
     $actions['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->getRequest());
     return $actions;
 }

作者:shrimal    项目:ahswe   
/**
  * {@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);
     }
 }

作者:justincletu    项目:webdrupalpr   
/**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state, GroupInterface $group = NULL)
 {
     $group = $this->entity;
     if (!$group->isNew()) {
         $form['#title'] = $this->t('Edit group %label', array('%label' => $group->label()));
     }
     $form = parent::form($form, $form_state, $group);
     return $form;
 }

作者:DrupalCamp-NY    项目:dcnyc1   
/**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     /** @var \Drupal\contact\MessageInterface $message */
     $message = $this->entity;
     $form = parent::form($form, $form_state, $message);
     $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Author name'), '#maxlength' => 255, '#default_value' => $message->getSenderName());
     $form['mail'] = array('#type' => 'email', '#title' => $this->t('Sender email address'), '#default_value' => $message->getSenderMail());
     return $form;
 }

作者:nstiela    项目:drops-   
/**
  * {@inheritdoc}
  */
 public function buildEntity(array $form, FormStateInterface $form_state)
 {
     $term = parent::buildEntity($form, $form_state);
     // Prevent leading and trailing spaces in term names.
     $term->setName(trim($term->getName()));
     // Assign parents with proper delta values starting from 0.
     $term->parent = array_keys($form_state->getValue('parent'));
     return $term;
 }

作者:jeyra    项目:camp-gd   
/**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $entity = $this->entity;
     // @todo: Is there a better way to check if an entity type is revisionable?
     if ($entity->getEntityType()->hasKey('revision') && !$entity->isNew()) {
         $form['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $entity->isNewRevision());
     }
     return $form;
 }

作者:alnutil    项目:drunatr   
/**
  * Overrides \Drupal\Core\Entity\EntityForm::submit().
  */
 public function submit(array $form, array &$form_state)
 {
     // Build the entity object from the submitted values.
     $entity = parent::submit($form, $form_state);
     // Save as a new revision if requested to do so.
     if (!empty($form_state['values']['revision'])) {
         $entity->setNewRevision();
     }
     return $entity;
 }

作者:AshishNaik02    项目:iimisac-d   
public function save(array $form, FormStateInterface $form_state) {
    /** @var FillPdfFormInterface $entity */
    $entity = $this->entity;

    $form_state->setRedirect('entity.fillpdf_form.edit_form', [
      'fillpdf_form' => $this->entity->fillpdf_form->target_id,
    ]);

    return parent::save($form, $form_state);
  }

作者:davidsoloma    项目:drupalconsole.co   
/**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $entity = $this->entity;
     $form['langcode'] = array('#title' => t('Language'), '#type' => 'language_select', '#default_value' => $entity->getUntranslated()->language()->getId(), '#languages' => LanguageInterface::STATE_ALL);
     // @todo: Is there a better way to check if an entity type is revisionable?
     if ($entity->getEntityType()->hasKey('revision') && !$entity->isNew()) {
         $form['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $entity->isNewRevision());
     }
     return $form;
 }

作者:sedurz    项目:ildeposito   
/**
  * {@inheritdoc}
  */
 protected function flagViolations(EntityConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state)
 {
     // Manually flag violations of fields not handled by the form display. This
     // is necessary as entity form displays only flag violations for fields
     // contained in the display.
     $field_names = array('label', 'machine_name');
     foreach ($violations->getByFields($field_names) as $violation) {
         list($field_name) = explode('.', $violation->getPropertyPath(), 2);
         $form_state->setErrorByName($field_name, $violation->getMessage());
     }
     parent::flagViolations($violations, $form, $form_state);
 }


问题


面经


文章

微信
公众号

扫码关注公众号