• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Field\WidgetBase类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Drupal\Core\Field\WidgetBase的典型用法代码示例。如果您正苦于以下问题:PHP WidgetBase类的具体用法?PHP WidgetBase怎么用?PHP WidgetBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了WidgetBase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: submitCleanFormState

  /**
   * Cleans up the form state for a submitted entity form.
   *
   * After field_attach_submit() has run and the form has been closed, the form
   * state still contains field data in $form_state->get('field'). Unless that
   * data is removed, the next form with the same #parents (reopened add form,
   * for example) will contain data (i.e. uploaded files) from the previous form.
   *
   * @param $entity_form
   *   The entity form.
   * @param $form_state
   *   The form state of the parent form.
   */
  public static function submitCleanFormState(&$entity_form, FormStateInterface $form_state) {
    $info = \Drupal::entityTypeManager()->getDefinition($entity_form['#entity_type']);
    if (!$info->get('field_ui_base_route')) {
      // The entity type is not fieldable, nothing to cleanup.
      return;
    }

    $bundle = $entity_form['#entity']->bundle();
    $instances = \Drupal::service('entity_field.manager')->getFieldDefinitions($entity_form['#entity_type'], $bundle);
    foreach ($instances as $instance) {
      $field_name = $instance->getName();
      if (!empty($entity_form[$field_name]['#parents'])) {
        $parents = $entity_form[$field_name]['#parents'];
        array_pop($parents);
        if (!empty($parents)) {
          $field_state = array();
          WidgetBase::setWidgetState($parents, $field_name, $form_state, $field_state);
        }
      }
    }
  }
开发者ID:joebachana,项目名称:usatne,代码行数:34,代码来源:EntityInlineForm.php


示例2: extractFormValues

 /**
  * {@inheritdoc}
  */
 public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state)
 {
     if ($this->isDefaultValueWidget($form_state)) {
         $items->filterEmptyItems();
         return;
     }
     $field_name = $this->fieldDefinition->getName();
     $path = array_merge($form['#parents'], array($field_name));
     $submitted_values = $form_state->getValue($path);
     $values = [];
     foreach ($items as $delta => $value) {
         $this->setIefId(sha1($items->getName() . '-ief-single-' . $delta));
         /** @var \Drupal\Core\Entity\EntityInterface $entity */
         if (!($entity = $form_state->get(['inline_entity_form', $this->getIefId(), 'entity']))) {
             return;
         }
         $values[$submitted_values[$delta]['_weight']] = ['entity' => $entity];
     }
     // Sort items base on weights.
     ksort($values);
     $values = array_values($values);
     // Let the widget massage the submitted values.
     $values = $this->massageFormValues($values, $form, $form_state);
     // Assign the values and remove the empty ones.
     $items->setValue($values);
     $items->filterEmptyItems();
     // Put delta mapping in $form_state, so that flagErrors() can use it.
     $field_name = $this->fieldDefinition->getName();
     $field_state = WidgetBase::getWidgetState($form['#parents'], $field_name, $form_state);
     foreach ($items as $delta => $item) {
         $field_state['original_deltas'][$delta] = isset($item->_original_delta) ? $item->_original_delta : $delta;
         unset($item->_original_delta, $item->_weight);
     }
     WidgetBase::setWidgetState($form['#parents'], $field_name, $form_state, $field_state);
 }
开发者ID:atif-shaikh,项目名称:DCX-Profile,代码行数:38,代码来源:InlineEntityFormSimple.php


示例3: extractFormValues

 /**
  * {@inheritdoc}
  */
 public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state)
 {
     if ($this->isDefaultValueWidget($form_state)) {
         $items->filterEmptyItems();
         return;
     }
     if (!$this->isSubmitRelevant($form, $form_state)) {
         return;
     }
     $field_name = $this->fieldDefinition->getName();
     // Extract the values from $form_state->getValues().
     $parents = array_merge($form['#parents'], [$field_name, 'form']);
     $ief_id = sha1(implode('-', $parents));
     $this->setIefId($ief_id);
     $inline_entity_form_state = $form_state->get('inline_entity_form');
     if (isset($inline_entity_form_state[$this->getIefId()])) {
         $values = $inline_entity_form_state[$this->getIefId()];
         $key_exists = TRUE;
     } else {
         $values = [];
         $key_exists = FALSE;
     }
     if ($key_exists) {
         $values = $values['entities'];
         // Account for drag-and-drop reordering if needed.
         if (!$this->handlesMultipleValues()) {
             // Remove the 'value' of the 'add more' button.
             unset($values['add_more']);
             // The original delta, before drag-and-drop reordering, is needed to
             // route errors to the corect form element.
             foreach ($values as $delta => &$value) {
                 $value['_original_delta'] = $delta;
             }
             usort($values, function ($a, $b) {
                 return SortArray::sortByKeyInt($a, $b, '_weight');
             });
         }
         foreach ($values as $delta => &$item) {
             /** @var \Drupal\Core\Entity\EntityInterface $entity */
             $entity = $item['entity'];
             if (!empty($item['needs_save'])) {
                 $entity->save();
             }
             if (!empty($item['delete'])) {
                 $entity->delete();
                 unset($items[$delta]);
             }
         }
         // Let the widget massage the submitted values.
         $values = $this->massageFormValues($values, $form, $form_state);
         // Assign the values and remove the empty ones.
         $items->setValue($values);
         $items->filterEmptyItems();
         // Put delta mapping in $form_state, so that flagErrors() can use it.
         $field_state = WidgetBase::getWidgetState($form['#parents'], $field_name, $form_state);
         foreach ($items as $delta => $item) {
             $field_state['original_deltas'][$delta] = isset($item->_original_delta) ? $item->_original_delta : $delta;
             unset($item->_original_delta, $item->_weight);
         }
         WidgetBase::setWidgetState($form['#parents'], $field_name, $form_state, $field_state);
     }
 }
开发者ID:tedbow,项目名称:scheduled-updates-demo,代码行数:65,代码来源:InlineEntityFormComplex.php


示例4: flagErrors

 /**
  * {@inheritdoc}
  */
 public function flagErrors(FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state)
 {
     // Never flag validation errors for the remove button.
     $clicked_button = end($form_state->getTriggeringElement()['#parents']);
     if ($clicked_button !== 'remove_button') {
         parent::flagErrors($items, $violations, $form, $form_state);
     }
 }
开发者ID:vinodpanicker,项目名称:drupal-under-the-hood,代码行数:11,代码来源:FileWidget.php


示例5: __construct

 /**
  * Constructs a new instance.
  *
  * @param string $plugin_id
  *   The plugin_id for the widget.
  * @param mixed[] $plugin_definition
  *   The plugin implementation definition.
  * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
  *   The definition of the field to which the widget is associated.
  * @param mied[] $settings
  *   The widget settings.
  * @param array[] $third_party_settings
  *   Any third party settings.
  * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
  *   The config factory.
  * @param \Drupal\Core\Session\AccountInterface $current_user
  *   The current user.
  * @param \Drupal\payment_reference\PaymentFactoryInterface $payment_factory
  *   The payment reference factory.
  */
 public function __construct($plugin_id, array $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, ConfigFactoryInterface $config_factory, AccountInterface $current_user, PaymentFactoryInterface $payment_factory)
 {
     parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
     $this->configFactory = $config_factory;
     $this->currentUser = $current_user;
     $this->paymentFactory = $payment_factory;
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:27,代码来源:PaymentReference.php


示例6: settingsForm

 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $elements = parent::settingsForm($form, $form_state);
     $elements['placeholder_isbn_13'] = array('#type' => 'textfield', '#title' => $this->t('Placeholder for ISBN 13'), '#default_value' => $this->getSetting('placeholder_isbn_13'), '#description' => $this->t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'));
     $elements['placeholder_isbn_10'] = array('#type' => 'textfield', '#title' => $this->t('Placeholder for ISBN 10'), '#default_value' => $this->getSetting('placeholder_isbn_10'), '#description' => $this->t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'));
     return $elements;
 }
开发者ID:Happyculture,项目名称:exercices,代码行数:10,代码来源:IsbnWidget.php


示例7: defaultSettings

 /**
  * {@inheritdoc}
  */
 public static function defaultSettings() {
   return [
     'autocomplete_threshold' => 7,
     'autocomplete_size' => 60,
     'autocomplete_placeholder' => '',
   ] + parent::defaultSettings();
 }
开发者ID:housineali,项目名称:drpl8_dv,代码行数:10,代码来源:EntitySelectWidget.php


示例8: settingsForm

 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $element = parent::settingsForm($form, $form_state);
     $element['size'] = array('#type' => 'number', '#title' => t('Size'), '#default_value' => $this->getSetting('size'), '#required' => TRUE, '#min' => 20);
     $element['placeholder'] = array('#type' => 'textfield', '#title' => t('Placeholder'), '#default_value' => $this->getSetting('placeholder'));
     return $element;
 }
开发者ID:C4AProjects,项目名称:c4apage,代码行数:10,代码来源:CountryAutocompleteWidget.php


示例9: settingsForm

 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $elements = parent::settingsForm($form, $form_state);
     $elements['field'] = array('#type' => 'select', '#weight' => 10, '#title' => $this->t('Field to use'), '#description' => $this->t('Select which field you would like to use.'), '#default_value' => $this->getSetting('field'), '#required' => TRUE, '#options' => $this->getAvailableFields());
     $enabled_plugins = array();
     $i = 0;
     foreach ($this->getSetting('provider_plugins') as $plugin_id => $plugin) {
         if ($plugin['checked']) {
             $plugin['weight'] = intval($i++);
             $enabled_plugins[$plugin_id] = $plugin;
         }
     }
     $elements['geocoder_plugins_title'] = array('#type' => 'item', '#weight' => 15, '#title' => t('Geocoder plugin(s)'), '#description' => t('Select the Geocoder plugins to use, you can reorder them. The first one to return a valid value will be used.'));
     $elements['provider_plugins'] = array('#type' => 'table', '#weight' => 20, '#header' => array(array('data' => $this->t('Enabled')), array('data' => $this->t('Weight')), array('data' => $this->t('Name'))), '#tabledrag' => array(array('action' => 'order', 'relationship' => 'sibling', 'group' => 'provider_plugins-order-weight')));
     $rows = array();
     $count = count($enabled_plugins);
     foreach (Geocoder::getPlugins('Provider') as $plugin_id => $plugin_name) {
         if (isset($enabled_plugins[$plugin_id])) {
             $weight = $enabled_plugins[$plugin_id]['weight'];
         } else {
             $weight = $count++;
         }
         $rows[$plugin_id] = array('#attributes' => array('class' => array('draggable')), '#weight' => $weight, 'checked' => array('#type' => 'checkbox', '#default_value' => isset($enabled_plugins[$plugin_id]) ? 1 : 0), 'weight' => array('#type' => 'weight', '#title' => t('Weight for @title', array('@title' => $plugin_id)), '#title_display' => 'invisible', '#default_value' => $weight, '#attributes' => array('class' => array('provider_plugins-order-weight'))), 'name' => array('#plain_text' => $plugin_name));
     }
     uasort($rows, function ($a, $b) {
         return strcmp($a['#weight'], $b['#weight']);
     });
     foreach ($rows as $plugin_id => $row) {
         $elements['provider_plugins'][$plugin_id] = $row;
     }
     $elements['dumper_plugin'] = array('#type' => 'select', '#weight' => 25, '#title' => 'Output format', '#default_value' => $this->getSetting('dumper_plugin'), '#options' => Geocoder::getPlugins('dumper'), '#description' => t('Set the output format of the value. Ex, for a geofield, the format must be set to WKT.'));
     $elements['delta_handling'] = array('#type' => 'select', '#weight' => 30, '#title' => $this->t('Multi-value input handling'), '#description' => $this->t('Should geometries from multiple inputs be: <ul><li>Matched with each input (e.g. One POINT for each address field)</li><li>Aggregated into a single MULTIPOINT geofield (e.g. One MULTIPOINT polygon from multiple address fields)</li><li>Broken up into multiple geometries (e.g. One MULTIPOINT to multiple POINTs.)</li></ul>'), '#default_value' => $this->getSetting('delta_handling'), '#options' => $this->getDeltaHandling(), '#required' => TRUE);
     return $elements;
 }
开发者ID:seongbae,项目名称:drumo-distribution,代码行数:37,代码来源:GeocodeWidgetBase.php


示例10: settingsSummary

 /**
  * {@inheritdoc}
  */
 public function settingsSummary()
 {
     $summary = parent::settingsSummary();
     $viewMode = ucfirst($this->getSetting('view_mode'));
     $summary[] = t('View mode: @view_mode', array('@view_mode' => $viewMode));
     return $summary;
 }
开发者ID:shrimala,项目名称:ahsweb,代码行数:10,代码来源:DisplayWidget.php


示例11: defaultSettings

 /**
  * {@inheritdoc}
  */
 public static function defaultSettings()
 {
     foreach (['first', 'second'] as $subfield) {
         $settings[$subfield] = ['type' => 'textfield', 'prefix' => '', 'suffix' => '', 'size' => 10, 'placeholder' => '', 'label' => t('Ok'), 'cols' => 10, 'rows' => 5];
     }
     $settings['inline'] = FALSE;
     return $settings + parent::defaultSettings();
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:11,代码来源:DoubleField.php


示例12: form

 /**
  * {@inheritdoc}
  */
 public function form(FieldItemListInterface $items, array &$form, FormStateInterface $form_state, $get_delta = NULL)
 {
     $ret = parent::form($items, $form, $form_state, $get_delta);
     $field_name = $this->fieldDefinition->getName();
     // Add a new wrapper around all the elements for Ajax replacement.
     $ret['#prefix'] = '<div id="' . $field_name . '-ajax-wrapper">';
     $ret['#suffix'] = '</div>';
     return $ret;
 }
开发者ID:atif-shaikh,项目名称:DCX-Profile,代码行数:12,代码来源:FieldCollectionEmbedWidget.php


示例13: defaultSettings

    /**
     * {@inheritdoc}
     */
    public static function defaultSettings()
    {
        return array('default_colors' => '
#AC725E,#D06B64,#F83A22,#FA573C,#FF7537,#FFAD46
#42D692,#16A765,#7BD148,#B3DC6C,#FBE983
#92E1C0,#9FE1E7,#9FC6E7,#4986E7,#9A9CFF
#B99AFF,#C2C2C2,#CABDBF,#CCA6AC,#F691B2
#CD74E6,#A47AE2') + parent::defaultSettings();
    }
开发者ID:zindont,项目名称:emormapping,代码行数:12,代码来源:ColorFieldWidgetBox.php


示例14: __construct

  /**
   * Constructs a new PriceDefaultWidget object.
   *
   * @param string $pluginId
   *   The plugin_id for the widget.
   * @param mixed $pluginDefinition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Field\FieldDefinitionInterface $fieldDefinition
   *   The definition of the field to which the widget is associated.
   * @param array $settings
   *   The widget settings.
   * @param array $thirdPartySettings
   *   Any third party settings.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   *   The entity type manager.
   * @param \Drupal\commerce_price\NumberFormatterFactoryInterface $numberFormatterFactory
   *   The number formatter factory.
   */
  public function __construct($pluginId, $pluginDefinition, FieldDefinitionInterface $fieldDefinition, array $settings, array $thirdPartySettings, EntityTypeManagerInterface $entityTypeManager, NumberFormatterFactoryInterface $numberFormatterFactory) {
    parent::__construct($pluginId, $pluginDefinition, $fieldDefinition, $settings, $thirdPartySettings);

    $this->currencyStorage = $entityTypeManager->getStorage('commerce_currency');
    $this->numberFormatter = $numberFormatterFactory->createInstance(NumberFormatterInterface::DECIMAL);
    $this->numberFormatter->setMinimumFractionDigits(0);
    $this->numberFormatter->setMaximumFractionDigits(6);
    $this->numberFormatter->setGroupingUsed(FALSE);
  }
开发者ID:housineali,项目名称:drpl8_dv,代码行数:27,代码来源:PriceDefaultWidget.php


示例15: massageFormValues

 /**
  * @inheritdoc
  *
  * N.B. massageFormValues and $element['#element_validate'] do comparable things.
  */
 public function massageFormValues(array $values, array $form, FormStateInterface $form_state)
 {
     $values = parent::massageFormValues($values, $form, $form_state);
     // Convert the values to real languagecodes,
     // but ONLY on Entity form, NOT in the 'field settings - default value'.
     if (isset($form_state->getBuildInfo()['form_id']) && $form_state->getBuildInfo()['form_id'] !== 'field_config_edit_form') {
         foreach ($values as &$value) {
             $value['value'] = LanguageItem::_getLanguageConfigurationValues($value['value']);
         }
     }
     return $values;
 }
开发者ID:dev981,项目名称:gaptest,代码行数:17,代码来源:LanguageSelectWidget.php


示例16: settingsForm

 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $elements = parent::settingsForm($form, $form_state);
     $entityFieldDefinitions = \Drupal::entityManager()->getFieldDefinitions($this->fieldDefinition->entity_type, $this->fieldDefinition->bundle);
     $options = array();
     foreach ($entityFieldDefinitions as $id => $definition) {
         if ($definition->getType() == 'geofield') {
             $options[$id] = $definition->getLabel();
         }
     }
     $elements['destination_field'] = array('#type' => 'select', '#title' => $this->t('Destination Geo Field'), '#default_value' => $this->getSetting('destination_field'), '#required' => TRUE, '#options' => $options);
     $elements['placeholder'] = array('#type' => 'textfield', '#title' => t('Placeholder'), '#default_value' => $this->getSetting('placeholder'), '#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'));
     return $elements;
 }
开发者ID:seongbae,项目名称:drumo-distribution,代码行数:17,代码来源:GeocoderWidget.php


示例17: onDependencyRemoval

 /**
  * {@inheritdoc}
  */
 public function onDependencyRemoval(array $dependencies)
 {
     $changed = parent::onDependencyRemoval($dependencies);
     // Only the setting 'role' is resolved here. When the dependency related to
     // this setting is removed, is expected that the widget component will be
     // update accordingly in the display entity. The 'role2' setting is
     // deliberately left out from being updated. When the dependency
     // corresponding to this setting is removed, is expected that the widget
     // component will be disabled in the display entity.
     if (!empty($role_id = $this->getSetting('role'))) {
         if (!empty($dependencies['config']["user.role.{$role_id}"])) {
             $this->setSetting('role', 'anonymous');
             $changed = TRUE;
         }
     }
     return $changed;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:20,代码来源:TestFieldWidget.php


示例18: massageFormValues

 /**
  * {@inheritdoc}
  */
 public function massageFormValues(array $values, array $form, FormStateInterface $form_state)
 {
     $values = parent::massageFormValues($values, $form, $form_state);
     // It is likely that the url provided for this field is not existing and
     // so the logic in the parent method did not set any defaults. Just run
     // through all url values and add defaults.
     foreach ($values as &$value) {
         if (!empty($value['path'])) {
             // In case we have query process the url.
             if (strpos($value['path'], '?') !== FALSE) {
                 $url = UrlHelper::parse($value['path']);
                 $value['path'] = $url['path'];
                 $value['query'] = $url['query'];
             }
         }
     }
     return $values;
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:21,代码来源:RedirectSourceWidget.php


示例19: __construct

 /**
  * {@inheritdoc}
  */
 public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings)
 {
     parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
     $property_names = $this->fieldDefinition->getFieldStorageDefinition()->getPropertyNames();
     $this->column = $property_names[0];
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:9,代码来源:OptionsWidgetBase.php


示例20: flagErrors

 /**
  * {@inheritdoc}
  *
  * Override the '%uri' message parameter, to ensure that 'internal:' URIs
  * show a validation error message that doesn't mention that scheme.
  */
 public function flagErrors(FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state)
 {
     /** @var \Symfony\Component\Validator\ConstraintViolationInterface $violation */
     foreach ($violations as $offset => $violation) {
         $parameters = $violation->getParameters();
         if (isset($parameters['@uri'])) {
             $parameters['@uri'] = static::getUriAsDisplayableString($parameters['@uri']);
             $violations->set($offset, new ConstraintViolation($this->t($violation->getMessageTemplate(), $parameters), $violation->getMessageTemplate(), $parameters, $violation->getRoot(), $violation->getPropertyPath(), $violation->getInvalidValue(), $violation->getPlural(), $violation->getCode()));
         }
     }
     parent::flagErrors($items, $violations, $form, $form_state);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:18,代码来源:LinkWidget.php



注:本文中的Drupal\Core\Field\WidgetBase类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Form\ConfigFormBase类代码示例发布时间:2022-05-23
下一篇:
PHP Field\FormatterBase类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap