当前位置: 首页>>代码示例>>PHP>>正文


PHP Field\WidgetBase类代码示例

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


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

示例3: __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

示例4: 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

示例5: defaultSettings

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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: __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

示例13: 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

示例14: 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

示例15: 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


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