本文整理汇总了PHP中Drupal\views\Plugin\views\style\StylePluginBase::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP StylePluginBase::validate方法的具体用法?PHP StylePluginBase::validate怎么用?PHP StylePluginBase::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\views\Plugin\views\style\StylePluginBase
的用法示例。
在下文中一共展示了StylePluginBase::validate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Validates the view configuration.
* Fails if there is a non-image field, or there are more
* than one image fields that are not excluded from display.
*/
function validate()
{
$errors = parent::validate();
if ($this->view->storage->isNew()) {
// Skip validation when the view is being created.
// (the default field is a title field, which would fail.)
return $errors;
}
// Get a list of fields that have been added to the display.
$fields = $this->displayHandler->handlers['field'];
// Check if there is exactly one image field to display.
$fields_valid = TRUE;
$field_count = 0;
foreach ($fields as $key => $field) {
// Ignore fields excluded from display.
if (!empty($field->options['exclude'])) {
continue;
}
// Determine the field's type.
$field_storage_definitions = \Drupal::entityManager()->getFieldStorageDefinitions($field->definition['entity_type']);
$field_type = $field_storage_definitions[$field->field]->getType();
if ($field_type != 'image') {
// Cannot display non-image fields. That would break the image grid.
$fields_valid = FALSE;
break;
}
$field_count++;
}
if (!$fields_valid || $field_count > 1) {
$errors[] = $this->t('This format can display only one image field and no other fields.');
}
return $errors;
}
示例2: validate
/**
* {@inheritdoc}
*/
public function validate()
{
$errors = parent::validate();
$pager_options = $this->displayHandler->getOption('pager');
if (isset($pager_options['type']) && !($pager_options['type'] == 'none' || $pager_options['type'] == 'some')) {
// @todo: Re-enable this error once issue #2579931 is resolved.
// $errors[] = $this->stringTranslation->translate('The Juicebox style cannot be used with a pager. Please disable the "Use a pager" option for this display.');
}
$style = $this->displayHandler->getOption('style');
// We want to somewhat "nag" the user if they have not yet configured the
// Juicebox-specific plugin settings (because things won't work until they
// do). However, we do NOT want to formally set an error. This is because
// this validate method can run on pages where the user can't actaully touch
// the Juicebox-specific plugin settings (such as
// admin/structure/views/add).
if (empty($style['options']['image_field']) || empty($style['options']['thumb_field'])) {
drupal_set_message($this->stringTranslation->translate("To ensure a fully functional Juicebox gallery please remember to add at least one field of type Image, File or File ID to your Juicebox view display, and to configure all Juicebox Gallery format settings. Once you have completed these steps, re-save your view to remove this warning."), 'warning', FALSE);
}
return $errors;
}
示例3: validate
/**
* {@inheritdoc}
*/
public function validate()
{
$errors = parent::validate();
$display_id = $this->displayHandler->display['id'];
if ($display_id == 'default') {
// @todo Update default display in templates to validate.
return $errors;
}
// @todo Validate row plugin
$argument = CalendarHelper::getDateArgumentHandler($this->view, $display_id);
if (empty($argument)) {
$errors[] = $this->t('\\Drupal\\calendar\\Plugin\\views\\style\\CalendarStyle: A calendar date argument is required when using the calendar style, but it is missing or is not using the default date.');
}
return $errors;
}
示例4: validate
/**
* {@inheritdoc}
*/
public function validate()
{
if ($this->displayHandler->display['display_plugin'] != 'default' && !$this->parseFields()) {
drupal_set_message(t('Display "@display" requires at least one date field.', array('@display' => $this->displayHandler->display['display_title'])), 'error');
}
return parent::validate();
}