コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildForm($form, $form_state);
     /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     $entity = $this->getEntity();
     if ($entity->isDefaultTranslation()) {
         if (count($entity->getTranslationLanguages()) > 1) {
             $languages = [];
             foreach ($entity->getTranslationLanguages() as $language) {
                 $languages[] = $language->getName();
             }
             $form['deleted_translations'] = array('#theme' => 'item_list', '#title' => $this->t('The following @entity-type translations will be deleted:', ['@entity-type' => $entity->getEntityType()->getLowercaseLabel()]), '#items' => $languages);
             $form['actions']['submit']['#value'] = $this->t('Delete all translations');
         }
     } else {
         $form['actions']['submit']['#value'] = $this->t('Delete @language translation', array('@language' => $entity->language()->getName()));
     }
     return $form;
 }
コード例 #2
0
ファイル: UserCancelForm.php プロジェクト: shumer/blog
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, array &$form_state)
 {
     $user = $this->currentUser();
     $this->cancelMethods = user_cancel_methods();
     // Display account cancellation method selection, if allowed.
     $admin_access = $user->hasPermission('administer users');
     $form['user_cancel_method'] = array('#type' => 'radios', '#title' => $this->entity->id() == $user->id() ? $this->t('When cancelling your account') : $this->t('When cancelling the account'), '#access' => $admin_access || $user->hasPermission('select account cancellation method'));
     $form['user_cancel_method'] += $this->cancelMethods;
     // Allow user administrators to skip the account cancellation confirmation
     // mail (by default), as long as they do not attempt to cancel their own
     // account.
     $override_access = $admin_access && $this->entity->id() != $user->id();
     $form['user_cancel_confirm'] = array('#type' => 'checkbox', '#title' => $this->t('Require email confirmation to cancel account.'), '#default_value' => !$override_access, '#access' => $override_access, '#description' => $this->t('When enabled, the user must confirm the account cancellation via email.'));
     // Also allow to send account canceled notification mail, if enabled.
     $default_notify = $this->config('user.settings')->get('notify.status_canceled');
     $form['user_cancel_notify'] = array('#type' => 'checkbox', '#title' => $this->t('Notify user when account is canceled.'), '#default_value' => $override_access ? FALSE : $default_notify, '#access' => $override_access && $default_notify, '#description' => $this->t('When enabled, the user will receive an email notification after the account has been canceled.'));
     // Always provide entity id in the same form key as in the entity edit form.
     $form['uid'] = array('#type' => 'value', '#value' => $this->entity->id());
     $form = parent::buildForm($form, $form_state);
     return $form;
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $instances = $this->entity->getInstances();
     $form['message'] = array('#markup' => format_plural(count($instances), 'This will also remove 1 placed block instance.', 'This will also remove @count placed block instances.'), '#access' => !empty($instances));
     return parent::buildForm($form, $form_state);
 }