本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::isValueEmpty方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::isValueEmpty方法的具体用法?PHP FormStateInterface::isValueEmpty怎么用?PHP FormStateInterface::isValueEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Form\FormStateInterface
的用法示例。
在下文中一共展示了FormStateInterface::isValueEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: form
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state)
{
$view = $this->entity;
$form['#prefix'] = '<div id="views-preview-wrapper" class="views-admin clearfix">';
$form['#suffix'] = '</div>';
$form['#id'] = 'views-ui-preview-form';
$form_state->disableCache();
$form['controls']['#attributes'] = array('class' => array('clearfix'));
$form['controls']['title'] = array('#prefix' => '<h2 class="view-preview-form__title">', '#markup' => $this->t('Preview'), '#suffix' => '</h2>');
// Add a checkbox controlling whether or not this display auto-previews.
$form['controls']['live_preview'] = array('#type' => 'checkbox', '#id' => 'edit-displays-live-preview', '#title' => $this->t('Auto preview'), '#default_value' => \Drupal::config('views.settings')->get('ui.always_live_preview'));
// Add the arguments textfield
$form['controls']['view_args'] = array('#type' => 'textfield', '#title' => $this->t('Preview with contextual filters:'), '#description' => $this->t('Separate contextual filter values with a "/". For example, %example.', array('%example' => '40/12/10')), '#id' => 'preview-args');
$args = array();
if (!$form_state->isValueEmpty('view_args')) {
$args = explode('/', $form_state->getValue('view_args'));
}
$user_input = $form_state->getUserInput();
if ($form_state->get('show_preview') || !empty($user_input['js'])) {
$form['preview'] = array('#weight' => 110, '#theme_wrappers' => array('container'), '#attributes' => array('id' => 'views-live-preview'), 'preview' => $view->renderPreview($this->displayID, $args));
}
$uri = $view->urlInfo('preview-form');
$uri->setRouteParameter('display_id', $this->displayID);
$form['#action'] = $uri->toString();
return $form;
}
示例2: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
// Process the upload and perform validation. Note: we're using the
// form value for the $replace parameter.
if (!$form_state->isValueEmpty('file_subdir')) {
$destination = 'temporary://' . $form_state->getValue('file_subdir');
file_prepare_directory($destination, FILE_CREATE_DIRECTORY);
} else {
$destination = FALSE;
}
// Setup validators.
$validators = array();
if ($form_state->getValue('is_image_file')) {
$validators['file_validate_is_image'] = array();
}
if ($form_state->getValue('allow_all_extensions')) {
$validators['file_validate_extensions'] = array();
} elseif (!$form_state->isValueEmpty('extensions')) {
$validators['file_validate_extensions'] = array($form_state->getValue('extensions'));
}
$file = file_save_upload('file_test_upload', $validators, $destination, 0, $form_state->getValue('file_test_replace'));
if ($file) {
$form_state->setValue('file_test_upload', $file);
drupal_set_message(t('File @filepath was uploaded.', array('@filepath' => $file->getFileUri())));
drupal_set_message(t('File name is @filename.', array('@filename' => $file->getFilename())));
drupal_set_message(t('File MIME type is @mimetype.', array('@mimetype' => $file->getMimeType())));
drupal_set_message(t('You WIN!'));
} elseif ($file === FALSE) {
drupal_set_message(t('Epic upload FAIL!'), 'error');
}
}
示例3: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
if (!$form_state->isValueEmpty('redirection')) {
if (!$form_state->isValueEmpty('destination')) {
// The destination is a random URL, so we can't use routed URLs.
// @todo Revist this in https://www.drupal.org/node/2418219.
$form_state->setRedirectUrl(Url::fromUserInput('/' . $form_state->getValue('destination')));
}
} else {
$form_state->disableRedirect();
}
}
示例4: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
if (!$form_state->isValueEmpty('redirection')) {
if (!$form_state->isValueEmpty('destination')) {
// @todo Use Url::fromPath() once https://www.drupal.org/node/2351379 is
// resolved.
$form_state->setRedirectUrl(Url::fromUri('base://' . $form_state->getValue('destination')));
}
} else {
$form_state->disableRedirect();
}
}
示例5: validateForm
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state)
{
$config = $this->config('simpletest.settings');
// If a username was provided but a password wasn't, preserve the existing
// password.
if (!$form_state->isValueEmpty('simpletest_httpauth_username') && $form_state->isValueEmpty('simpletest_httpauth_password')) {
$form_state->setValue('simpletest_httpauth_password', $config->get('httpauth.password'));
}
// If a password was provided but a username wasn't, the credentials are
// incorrect, so throw an error.
if ($form_state->isValueEmpty('simpletest_httpauth_username') && !$form_state->isValueEmpty('simpletest_httpauth_password')) {
$form_state->setErrorByName('simpletest_httpauth_username', $this->t('HTTP authentication credentials must include a username in addition to a password.'));
}
parent::validateForm($form, $form_state);
}
示例6: testIsValueEmpty
/**
* @covers ::isValueEmpty
*/
public function testIsValueEmpty()
{
$key = ['foo', 'bar'];
$is_empty = TRUE;
$this->decoratedFormState->isValueEmpty($key)->willReturn($is_empty)->shouldBeCalled();
$this->assertSame($is_empty, $this->formStateDecoratorBase->isValueEmpty($key));
}
示例7: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$paypal_config = $this->config('uc_paypal.settings');
$session = \Drupal::service('session');
$order = Order::load($session->get('cart_order'));
if (!$form_state->isValueEmpty('shippable')) {
$quote_option = explode('---', $form_state->getValue(['quotes', 'quote_option']));
$order->quote['method'] = $quote_option[0];
$order->quote['accessorials'] = $quote_option[1];
$method = ShippingQuoteMethod::load($quote_option[0]);
$label = $method['quote']['accessorials'][$quote_option[1]];
// $label = $method->label();
$quote_option = $form_state->getValue(['quotes', 'quote_option']);
$order->quote['rate'] = $form_state->getValue(['quotes', $quote_option, 'rate']);
$result = db_query("SELECT line_item_id FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", [':id' => $order->id(), ':type' => 'shipping']);
if ($lid = $result->fetchField()) {
uc_order_update_line_item($lid, $label, $order->quote['rate']);
} else {
uc_order_line_item_add($order->id(), 'shipping', $label, $order->quote['rate']);
}
}
if ($paypal_config->get('ec_review_company')) {
$order->delivery_company = $form_state->getValue('delivery_company');
}
if ($paypal_config->get('ec_review_phone')) {
$order->delivery_phone = $form_state->getValue('delivery_phone');
}
if ($paypal_config->get('ec_review_comment')) {
db_delete('uc_order_comments')->condition('order_id', $order->id())->execute();
uc_order_comment_save($order->id(), 0, $form_state->getValue('order_comments'), 'order');
}
$order->save();
$form_state->setRedirect('uc_paypal.ec_submit');
}
示例8: save
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state)
{
// Save as a new revision if requested to do so.
if (!$form_state->isValueEmpty('revision')) {
$this->entity->setNewRevision();
}
$insert = $this->entity->isNew();
$this->entity->save();
$context = ['@type' => $this->entity->bundle(), '%info' => $this->entity->label()];
$logger = $this->logger($this->entity->id());
$bundle_entity = $this->getBundleEntity();
$t_args = ['@type' => $bundle_entity ? $bundle_entity->label() : 'None', '%info' => $this->entity->label()];
if ($insert) {
$logger->notice('@type: added %info.', $context);
drupal_set_message($this->t('@type %info has been created.', $t_args));
} else {
$logger->notice('@type: updated %info.', $context);
drupal_set_message($this->t('@type %info has been updated.', $t_args));
}
if ($this->entity->id()) {
$form_state->setValue('id', $this->entity->id());
$form_state->set('id', $this->entity->id());
if ($this->entity->getEntityType()->hasLinkTemplate('collection')) {
$form_state->setRedirectUrl($this->entity->toUrl('collection'));
} else {
$form_state->setRedirectUrl($this->entity->toUrl('canonical'));
}
} else {
// In the unlikely case something went wrong on save, the entity will be
// rebuilt and entity form redisplayed.
drupal_set_message($this->t('The entity could not be saved.'), 'error');
$form_state->setRebuild();
}
}
示例9: validateForm
/**
* Implements \Drupal\Core\Form\FormInterface::validateForm().
*/
public function validateForm(array &$form, FormStateInterface $form_state)
{
$form_state->set('notify_emails', []);
if (!$form_state->isValueEmpty('update_notify_emails')) {
$valid = array();
$invalid = array();
foreach (explode("\n", trim($form_state->getValue('update_notify_emails'))) as $email) {
$email = trim($email);
if (!empty($email)) {
if ($this->emailValidator->isValid($email)) {
$valid[] = $email;
} else {
$invalid[] = $email;
}
}
}
if (empty($invalid)) {
$form_state->set('notify_emails', $valid);
} elseif (count($invalid) == 1) {
$form_state->setErrorByName('update_notify_emails', $this->t('%email is not a valid email address.', array('%email' => reset($invalid))));
} else {
$form_state->setErrorByName('update_notify_emails', $this->t('%emails are not valid email addresses.', array('%emails' => implode(', ', $invalid))));
}
}
parent::validateForm($form, $form_state);
}
示例10: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(OrderInterface $order, array &$form, FormStateInterface $form_state)
{
if (!$form_state->isValueEmpty('admin_comment')) {
$uid = \Drupal::currentUser()->id();
uc_order_comment_save($form_state->getValue('order_id'), $uid, $form_state->getValue('admin_comment'));
}
}
示例11: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
// Test discovery does not run upon form submission.
simpletest_classloader_register();
// This form accepts arbitrary user input for 'tests'.
// An invalid value will cause the $class_name lookup below to die with a
// fatal error. Regular user access mechanisms to this form are intact.
// The only validation effectively being skipped is the validation of
// available checkboxes vs. submitted checkboxes.
// @todo Refactor Form API to allow to POST values without constructing the
// entire form more easily, BUT retaining routing access security and
// retaining Form API CSRF #token security validation, and without having
// to rely on form caching.
$user_input = $form_state->getUserInput();
if ($form_state->isValueEmpty('tests') && !empty($user_input['tests'])) {
$form_state->setValue('tests', $user_input['tests']);
}
$tests_list = array();
foreach ($form_state->getValue('tests') as $class_name => $value) {
if ($value === $class_name) {
if (is_subclass_of($class_name, 'PHPUnit_Framework_TestCase')) {
$test_type = 'phpunit';
} else {
$test_type = 'simpletest';
}
$tests_list[$test_type][] = $class_name;
}
}
if (!empty($tests_list)) {
$test_id = simpletest_run_tests($tests_list, 'drupal');
$form_state->setRedirect('simpletest.result_form', array('test_id' => $test_id));
}
}
示例12: save
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state)
{
/** @var EntityTypeBaseInterface $entity_type */
$entities = $this->entity->type->referencedEntities();
$entity_type = reset($entities);
// Save as a new revision if requested to do so.
if (!$form_state->isValueEmpty('revision')) {
$this->entity->setNewRevision();
}
$insert = $this->entity->isNew();
$this->entity->save();
$context = ['@type' => $this->entity->bundle(), '%info' => $this->entity->label()];
$logger = $this->logger($this->entity->id());
$t_args = ['@type' => $entity_type->label(), '%info' => $this->entity->label()];
if ($insert) {
$logger->notice('@type: added %info.', $context);
drupal_set_message($this->t('@type %info has been created.', $t_args));
} else {
$logger->notice('@type: updated %info.', $context);
drupal_set_message($this->t('@type %info has been updated.', $t_args));
}
if ($this->entity->id()) {
$form_state->setValue('id', $this->entity->id());
$form_state->set('id', $this->entity->id());
$form_state->setRedirectUrl($this->entity->urlInfo('collection'));
} else {
// In the unlikely case something went wrong on save, the entity will be
// rebuilt and entity form redisplayed.
drupal_set_message($this->t('The entity could not be saved.'), 'error');
$form_state->setRebuild();
}
}
示例13: save
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state)
{
try {
$entity = $this->entity;
// Save as a new revision if requested to do so.
if (!$form_state->isValueEmpty('revision')) {
$entity->setNewRevision();
}
$is_new = $entity->isNew();
$entity->save();
if ($is_new) {
$message = t('%entity_type @id has been created.', array('@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId()));
} else {
$message = t('%entity_type @id has been updated.', array('@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId()));
}
drupal_set_message($message);
if ($entity->id()) {
$entity_type = $entity->getEntityTypeId();
$form_state->setRedirect("entity.{$entity_type}.edit_form", array($entity_type => $entity->id()));
} else {
// Error on save.
drupal_set_message(t('The entity could not be saved.'), 'error');
$form_state->setRebuild();
}
} catch (\Exception $e) {
\Drupal::state()->set('entity_test.form.save.exception', get_class($e) . ': ' . $e->getMessage());
}
}
示例14: process
/**
* {@inheritdoc}
*/
public function process(OrderInterface $order, array $form, FormStateInterface $form_state)
{
db_delete('uc_order_comments')->condition('order_id', $order->id())->execute();
if (!$form_state->isValueEmpty(['panes', 'comments', 'comments'])) {
uc_order_comment_save($order->id(), 0, $form_state->getValue(['panes', 'comments', 'comments']), 'order', uc_order_state_default('post_checkout'), TRUE);
}
return TRUE;
}
示例15: validateForm
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state)
{
// If both fields are empty or filled, cancel.
$file_upload = $this->getRequest()->files->get('files[upload]', NULL, TRUE);
if ($form_state->isValueEmpty('remote') == empty($file_upload)) {
$form_state->setErrorByName('remote', $this->t('<em>Either</em> upload a file or enter a URL.'));
}
}