本文整理汇总了PHP中Drupal\Core\Entity\ContentEntityForm::buildForm方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentEntityForm::buildForm方法的具体用法?PHP ContentEntityForm::buildForm怎么用?PHP ContentEntityForm::buildForm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\ContentEntityForm
的用法示例。
在下文中一共展示了ContentEntityForm::buildForm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
/* @var $entity \Drupal\drupalbristol_sponsors\Entity\SponsorEntity */
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
return $form;
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$config = $this->entity->getConfiguration();
$manager = $this->entity->getType() == 'condition' ? 'conditionManager' : 'actionManager';
$this->plugin = $this->{$manager}->createInstance($this->entity->getPluginId(), $config);
return parent::buildForm($form, $form_state);
}
示例3: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
/* @var $entity \Drupal\component\Entity\Component */
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
return $form;
}
示例4: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
/* @var $entity \Drupal\drupal8_entity\Entity\Drupal8EntityItem */
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
$form['langcode'] = array('#title' => $this->t('Language'), '#type' => 'language_select', '#default_value' => $entity->langcode->value, '#languages' => Language::STATE_ALL);
return $form;
}
示例5: 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;
}
示例6: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$form = parent::buildForm($form, $form_state);
// The widgets are allowed to signal that the form should be hidden
// (because there's no purchasable entity to select, for example).
if ($form_state->get('hide_form')) {
$form['#access'] = FALSE;
}
return $form;
}
示例7: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
parent::buildForm($form, $form_state);
$roles = tmgmt_local_translator_roles();
if (empty($roles)) {
drupal_set_message(t('No user role has the "provide translation services" permission. <a href="@url">Configure permissions</a> for the Drupal user module.', array('@url' => URL::fromRoute('user.admin_permissions'))), 'warning');
}
$form['tuid'] = array('#title' => t('Assign to'), '#type' => 'select', '#empty_option' => t('- Select user -'), '#options' => tmgmt_local_get_assignees_for_tasks([$this->getEntity()->id()]), '#required' => TRUE);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Assign tasks'));
return $form;
}
示例8: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
/* @var $entity \Drupal\custom_page\Entity\CustomPage */
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
$form['metatags'] = array('#type' => 'details', '#title' => 'Meta tags');
$form['metatags']['meta_title'] = $form['meta_title'];
$form['metatags']['meta_description'] = $form['meta_description'];
unset($form['meta_title']);
unset($form['meta_description']);
return $form;
}
示例9: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
// Skip building the form if there are no available stores.
$store_query = $this->entityManager->getStorage('commerce_store')->getQuery();
if ($store_query->count()->execute() == 0) {
$options = ['query' => ['destination' => Url::fromRoute('<current>')->toString()]];
$link = Link::createFromRoute('Add a new store.', 'entity.commerce_store.add_page', [], $options);
$form['warning'] = ['#markup' => t("Products can't be created until a store has been added. @link", ['@link' => $link->toString()])];
return $form;
}
return parent::buildForm($form, $form_state);
}
示例10: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$form = parent::buildForm($form, $form_state);
$form['#title'] = $this->getQuestion();
$form['#attributes']['class'][] = 'confirmation';
$form['description'] = array('#markup' => $this->getDescription());
$form[$this->getFormName()] = array('#type' => 'hidden', '#value' => 1);
// By default, render the form using theme_confirm_form().
if (!isset($form['#theme'])) {
$form['#theme'] = 'confirm_form';
}
return $form;
}
示例11: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/* @var $entity \Drupal\product_search\Entity\PoliticalDivision */
$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;
}
示例12: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
/* @var $entity \Drupal\myeck\Entity\Myeck */
$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;
}
示例13: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
/* @var $entity \Drupal\quiz\Entity\Answer */
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
$question = $entity->getQuestion();
/* @var $question \Drupal\quiz\Entity\Question */
$question = $entity->getQuestion();
/* @var $question \Drupal\quiz\Entity\Question */
$quiz = $question->getQuiz();
$status = $quiz->getActiveStatus($this->currentUser());
/* @var $status \Drupal\quiz\Entity\UserQuizStatus */
if ($status == NULL) {
return $this->redirect('entity.quiz.canonical_user', ['quiz' => $question->getQuiz()->id()]);
}
if ($status->getCurrentQuestionId() != $question->id()) {
return $this->redirect('entity.quiz.canonical_user', ['quiz' => $question->getQuiz()->id()]);
}
$count = $question->getUserQuizStateAnswersCount($this->currentUser(), $status);
if ($count) {
$status->setLastQuestion($question);
$status->save();
return $this->redirect('entity.quiz.canonical_user', ['quiz' => $question->getQuiz()->id()]);
}
$form['langcode'] = array('#title' => $this->t('Language'), '#type' => 'language_select', '#default_value' => $entity->langcode->value, '#languages' => Language::STATE_ALL);
$form['question'] = array('#type' => 'label', '#title' => $entity->getQuestion()->get('question')->value, '#weight' => -5);
// Only display a timer if the quiz is timed.
//kint($quiz->get('time')->value);
if ($quiz->get('time')->value > 0) {
$form['timer'] = array('#markup' => '<div id="js-timer"></div>', '#weight' => -9);
$timeLeft = $quiz->get('time')->value + $status->get('started')->value - time();
//kint($timeLeft);
// If we're out of time we mark the status as finished, no matter if some questions were left unanswered.
if ($timeLeft < 0) {
$status->setFinished(time());
$status->setScore($status->evaluate());
$status->setMaxScore($quiz->getMaxScore());
$status->setPercent($quiz->get('percent')->value);
$status->setFinished(time());
$status->setQuestionsCount(count($quiz->getQuestions()));
$status->save();
//TODO: redirect to evaluation. And make status save a separate function in controller.
return $this->redirect('entity.quiz.canonical', ['quiz' => $quiz->id()]);
}
$form['#attached']['library'][] = 'quiz/quiz.timer';
$form['#attached']['drupalSettings']['quiz']['endtime'] = $timeLeft - 1;
}
return $form;
}
示例14: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
/* @var $entity \Drupal\rdf_entity\Entity\Rdf */
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
$type = RdfEntityType::load($entity->bundle());
if ($type->label()) {
// Add.
if ($entity->isNew()) {
$form['#title'] = $this->t('<em>Add @type</em>', array('@type' => $type->label()));
} else {
$form['#title'] = $this->t('<em>Edit @type</em> @title', array('@type' => $type->label(), '@title' => $entity->label()));
}
}
$form['langcode'] = array('#title' => $this->t('Language'), '#type' => 'language_select', '#default_value' => $entity->getUntranslated()->language()->getId(), '#languages' => Language::STATE_ALL);
return $form;
}
示例15: buildForm
/**
* {@inheritDoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$entity = $this->entity;
$state = \Drupal::state();
$form = parent::buildForm($form, $form_state);
// Due to #limit_validation_errors, submitting the form with the "Add" button
// will only expose validated values in the submit handler, so our storage may
// be incomplete. Therefore, the default values always have to be overloaded.
$stored_record = $entity->getStorageRecord();
$stored_record += array('exclude' => '', 'parent' => array('child' => ''), 'field' => array());
$storage = $form_state->get('mollom_test');
$storage = empty($storage) ? array() : $storage;
$stored_record = array_merge($stored_record, $storage);
// Always add an empty field the user can submit.
$stored_record['field']['new'] = '';
$form_state->set('mollom_test', $stored_record);
// Output a page view counter for page/form cache testing purposes.
$count = $state->get('mollom_test.view_count', 0);
$reset_link = \Drupal::l($this->t('Reset'), Url::fromRoute('mollom_test.views_reset', [], ['query' => $this->getDestinationArray()]));
$form['views'] = array('#markup' => '<p>' . 'Views: ' . $count++ . ' ' . $reset_link . '</p>');
$state->set('mollom_test.view_count', $count);
// Conditionally enable form caching.
if ($state->get('mollom_test.cache_form', FALSE)) {
$form_state->setCached(TRUE);
}
$form['#tree'] = TRUE;
$form['mid'] = array('#type' => 'hidden', '#value' => $stored_record['mid']);
$form['title'] = array('#type' => 'textfield', '#title' => 'Title', '#default_value' => $stored_record['title'], '#required' => TRUE);
$form['body'] = array('#type' => 'textfield', '#title' => 'Body', '#default_value' => $stored_record['body']);
$form['exclude'] = array('#type' => 'textfield', '#title' => 'Some other field', '#default_value' => $stored_record['exclude']);
$form['parent']['child'] = array('#type' => 'textfield', '#title' => 'Nested element', '#default_value' => $stored_record['parent']['child']);
$form['field'] = array('#type' => 'fieldset', '#title' => 'Field');
$weight = 0;
foreach ($stored_record['field'] as $delta => $value) {
$form['field'][$delta] = array('#type' => 'textfield', '#title' => 'Field ' . $delta, '#default_value' => $value, '#weight' => $weight++);
}
$form['field']['new']['#weight'] = 999;
$form['field']['submit'] = array('#type' => 'submit', '#value' => 'Add', '#limit_validation_errors' => array(array('field')), '#submit' => array('::fieldSubmitForm'), '#weight' => 1000);
$form['status'] = array('#type' => 'checkbox', '#title' => 'Published', '#default_value' => $stored_record['status'], '#access' => \Drupal::currentUser()->hasPermission('administer mollom'));
return $form;
}