本文整理汇总了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);
}
}
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例5: defaultSettings
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return [
'autocomplete_threshold' => 7,
'autocomplete_size' => 60,
'autocomplete_placeholder' => '',
] + parent::defaultSettings();
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}