本文整理汇总了PHP中Drupal\Core\Entity\ContentEntityForm类的典型用法代码示例。如果您正苦于以下问题:PHP ContentEntityForm类的具体用法?PHP ContentEntityForm怎么用?PHP ContentEntityForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContentEntityForm类的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())));
}
}
示例2: validate
/**
* {@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);
}
示例3: actions
/**
* {@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;
}
示例4: submit
/**
* 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;
}
示例5: validate
/**
* {@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);
}
示例6: actions
/**
* {@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;
}
示例7: form
/**
* {@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;
}
示例8: form
/**
* {@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);
}
示例9: actions
/**
* {@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;
}
示例10: buildForm
/**
* {@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;
}
示例11: actions
/**
* {@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;
}
示例12: 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);
}
}
示例13: form
/**
* {@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;
}
示例14: form
/**
* {@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;
}
示例15: buildEntity
/**
* {@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;
}