本文整理汇总了PHP中Drupal\views\Plugin\views\style\StylePluginBase类的典型用法代码示例。如果您正苦于以下问题:PHP StylePluginBase类的具体用法?PHP StylePluginBase怎么用?PHP StylePluginBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StylePluginBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Overrides \Drupal\views\Plugin\views\style\StylePluginBase\StylePluginBase::render().
*/
public function render()
{
if (!empty($this->view->live_preview)) {
return parent::render();
}
// Group the rows according to the grouping field, if specified.
$sets = $this->renderGrouping($this->view->result, $this->options['grouping']);
// Grab the alias of the 'id' field added by
// entity_reference_plugin_display.
$id_field_alias = $this->view->storage->get('base_field');
// @todo We don't display grouping info for now. Could be useful for select
// widget, though.
$results = array();
$this->view->row_index = 0;
foreach ($sets as $records) {
foreach ($records as $values) {
// Sanitize HTML, remove line breaks and extra whitespace.
$output = $this->view->rowPlugin->render($values);
$output = drupal_render($output);
$results[$values->{$id_field_alias}] = Xss::filterAdmin(preg_replace('/\\s\\s+/', ' ', str_replace("\n", '', $output)));
$this->view->row_index++;
}
}
unset($this->view->row_index);
return $results;
}
示例2: buildOptionsForm
/**
* Overrides Drupal\views\Plugin\views\style\StylePluginBase::buildOptionsForm().
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
// Get the mapping.
$mapping = $this->defineMapping();
// Restrict the list of defaults to the mapping, in case they have changed.
$options = array_intersect_key($this->options['mapping'], $mapping);
// Get the labels of the fields added to this display.
$field_labels = $this->displayHandler->getFieldLabels();
// Provide some default values.
$defaults = array('#type' => 'select', '#required' => FALSE, '#multiple' => FALSE);
// For each mapping, add a select element to the form.
foreach ($options as $key => $value) {
// If the field is optional, add a 'None' value to the top of the options.
$field_options = array();
$required = !empty($mapping[$key]['#required']);
if (!$required && empty($mapping[$key]['#multiple'])) {
$field_options = array('' => $this->t('- None -'));
}
$field_options += $field_labels;
// Optionally filter the available fields.
if (isset($mapping[$key]['#filter'])) {
$this->view->initHandlers();
$filter = $mapping[$key]['#filter'];
$this::$filter($field_options);
unset($mapping[$key]['#filter']);
}
// These values must always be set.
$overrides = array('#options' => $field_options, '#default_value' => $options[$key]);
// Optionally allow the select to be toggleable.
if (!empty($mapping[$key]['#toggle'])) {
$form['mapping']["toggle_{$key}"] = array('#type' => 'checkbox', '#title' => $this->t('Use a custom %field_name', array('%field_name' => strtolower($mapping[$key]['#title']))), '#default_value' => $this->options['mapping']["toggle_{$key}"]);
$overrides['#states']['visible'][':input[name="style_options[mapping][' . "toggle_{$key}" . ']"]'] = array('checked' => TRUE);
}
$form['mapping'][$key] = $overrides + $mapping[$key] + $defaults;
}
}
示例3: buildOptionsForm
/**
* Render the given style.
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
$form['type'] = array('#type' => 'radios', '#title' => $this->t('List type'), '#options' => array('ul' => $this->t('Unordered list'), 'ol' => $this->t('Ordered list')), '#default_value' => $this->options['type']);
$form['wrapper_class'] = array('#title' => $this->t('Wrapper class'), '#description' => $this->t('The class to provide on the wrapper, outside the list.'), '#type' => 'textfield', '#size' => '30', '#default_value' => $this->options['wrapper_class']);
$form['class'] = array('#title' => $this->t('List class'), '#description' => $this->t('The class to provide on the list element itself.'), '#type' => 'textfield', '#size' => '30', '#default_value' => $this->options['class']);
}
示例4: 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;
}
示例5: buildOptionsForm
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
$form['grid_style'] = array('#prefix' => '<h4>Grid Settings</h4>', '#type' => 'select', '#title' => t('Mode'), '#description' => t('Choose grid style:'), '#options' => array('classic' => t('Classic Grid'), 'masonry' => t('Masonry Simple'), 'masonry_resize' => t('Masonry Resize')), '#default_value' => $this->options['grid_style'], '#attributes' => array('class' => array('grid-style')));
$field_options = array();
$fields = \Drupal::entityManager()->getFieldMapByFieldType('image');
foreach ($fields as $field) {
foreach ($field as $key => $value) {
$field_options[$key] = $key;
}
}
$form['masonry_background'] = array('#type' => 'select', '#title' => t('Image'), '#options' => $field_options, '#default_value' => $this->options['masonry_background'], '#states' => array('visible' => array('.grid-style' => array('value' => 'masonry_resize'))));
$form['grid_ratio'] = array('#type' => 'textfield', '#title' => t('Ratio'), '#description' => t('The ratio image'), '#default_value' => $this->options['grid_ratio'], '#states' => array('visible' => array('.grid-style' => array('value' => 'masonry_resize'))));
$form['grid_cols_lg'] = array('#type' => 'select', '#title' => t('Large Desktop Items'), '#description' => t('Number of items on large desktop'), '#options' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12), '#default_value' => $this->options['grid_cols_lg']);
$form['grid_cols_md'] = array('#type' => 'select', '#title' => t('Desktop Items'), '#description' => t('Number of items on desktop'), '#options' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12), '#default_value' => $this->options['grid_cols_md']);
$form['grid_cols_sm'] = array('#type' => 'select', '#title' => t('Tablet Items'), '#description' => t('Number of items on tablet'), '#options' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12), '#default_value' => $this->options['grid_cols_sm']);
$form['grid_cols_xs'] = array('#type' => 'select', '#title' => t('Phone Items'), '#description' => t('Number of items on phone'), '#options' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12), '#default_value' => $this->options['grid_cols_xs']);
$form['grid_margin'] = array('#type' => 'textfield', '#title' => t('Margin'), '#description' => t('The spacing beetween items'), '#default_value' => $this->options['grid_margin'], '#field_suffix' => 'px');
$form['grid_filter'] = array('#type' => 'select', '#title' => t('Use Filter'), '#options' => array(0 => t('No'), 1 => t('Yes')), '#description' => t('Filter items by taxonomy term'), '#default_value' => $this->options['grid_filter'], '#attributes' => array('class' => array('grid-filter-option')));
$categories = array();
$categories['select'] = t('Select');
foreach (Vocabulary::loadMultiple() as $vocabulary) {
$categories[$vocabulary->id()] = $vocabulary->get('name');
}
$form['grid_filter_vocabulary'] = array('#type' => 'select', '#title' => t('Filter Vocabulary'), '#options' => $categories, '#description' => t('Which taxonomy vocabulary do you want to use for the filter'), '#default_value' => $this->options['grid_filter_vocabulary'], '#states' => array('visible' => array('.grid-filter-option' => array('value' => 1))));
}
示例6: defineOptions
protected function defineOptions()
{
$options = parent::defineOptions();
$options['base_path'] = array('default' => '');
$options['count'] = array('default' => TRUE, 'bool' => TRUE);
$options['override'] = array('default' => FALSE, 'bool' => TRUE);
$options['items_per_page'] = array('default' => 25);
return $options;
}
示例7: buildOptionsForm
/**
* Builds the configuration form.
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
$options = array('' => $this->t('- None -'));
$field_labels = $this->displayHandler->getFieldLabels(TRUE);
$options += $field_labels;
$form['date_field'] = array('#type' => 'select', '#title' => $this->t('Date'), '#options' => $options, '#default_value' => $this->options['date_field'], '#description' => $this->t('The field name of the date field that will be used as the date on the timeline.'));
$form['group_heading'] = array('#type' => 'select', '#title' => $this->t('Group heading'), '#options' => array('' => $this->t('No Heading'), 'century' => $this->t('Century'), 'date' => $this->t('Full Date'), 'format' => $this->t('Custom Format')), '#description' => $this->t('The type of date heading to add to the timeline. This heading will be inserted at the first spot where the value of the heading changes.'), '#default_value' => $this->options['group_heading']);
$form['group_heading_format'] = array('#type' => 'textfield', '#title' => $this->t('Group heading format'), '#description' => $this->t("If 'Custom Format' was selected above, input the format string to use for the date heading, using the formats from http://php.net/manual/en/function.date.php. For instance, 'M Y' will display a heading over all items with the same month and year, formatted as 'Jan 2016'."), '#default_value' => $this->options['group_heading_format']);
}
示例8: buildOptionsForm
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
$options = array('' => $this->t('- None -'));
$field_labels = $this->displayHandler->getFieldLabels(TRUE);
$options += $field_labels;
$grouping = $this->options['grouping'];
$form['grouping'] = array('#type' => 'select', '#title' => $this->t('Grouping field Nr.@number'), '#options' => $options, '#default_value' => $grouping, '#description' => $this->t('You may optionally specify a field by which to group the records. Leave blank to not group.'));
$a = '';
}
示例9: buildOptionsForm
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
$form['title_field'] = array('#type' => 'select', '#title' => $this->t('Title field'), '#options' => $this->displayHandler->getFieldLabels(TRUE), '#required' => TRUE, '#default_value' => $this->options['title_field'], '#description' => $this->t('Select the field that will be used as the title.'));
$form['accordion_filter'] = array('#type' => 'select', '#title' => t('Use Filter'), '#options' => array(0 => t('No'), 1 => t('Yes')), '#description' => t('Filter items by taxonomy term'), '#default_value' => $this->options['accordion_filter'], '#attributes' => array('class' => array('accordion-filter-option')));
$categories = array();
$categories['select'] = t('Select');
foreach (Vocabulary::loadMultiple() as $vocabulary) {
$categories[$vocabulary->id()] = $vocabulary->get('name');
}
$form['accordion_filter_vocabulary'] = array('#type' => 'select', '#title' => t('Filter Vocabulary'), '#options' => $categories, '#description' => t('Which taxonomy vocabulary do you want to use for the filter'), '#default_value' => $this->options['accordion_filter_vocabulary'], '#states' => array('visible' => array('.accordion-filter-option' => array('value' => 1))));
}
示例10: testRenderWithIdAndToken
/**
* @covers ::render
* @covers ::defineOptions
* @covers ::init
*
* @dataProvider providerTestTokens
*/
public function testRenderWithIdAndToken($token, $id)
{
$this->setupEntityManager();
$options = ['target' => $token, 'tokenize' => TRUE];
$entity = $this->getMock('Drupal\\Core\\Entity\\EntityInterface');
$entity->expects($this->once())->method('access')->willReturn(TRUE);
$this->stylePlugin->expects($this->once())->method('tokenizeValue')->with($token, 0)->willReturn($id);
$this->entityStorage->expects($this->never())->method('loadByProperties');
$this->entityStorage->expects($this->once())->method('load')->with($id)->willReturn($entity);
$this->entityViewBuilder->expects($this->once())->method('view')->with($entity, 'default')->willReturn(['#markup' => 'hallo']);
$this->entityHandler->init($this->executable, $this->display, $options);
$result = $this->entityHandler->render();
$this->assertEquals(['#markup' => 'hallo'], $result);
}
示例11: buildOptionsForm
/**
* Render the given style.
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
$form['items'] = array('#type' => 'number', '#title' => $this->t('Items'), '#description' => $this->t('Maximum amount of items displayed at a time with the widest browser width.'), '#default_value' => $this->options['items']);
$form['itemsDesktop'] = array('#type' => 'textfield', '#title' => $this->t('Items Desktop'), '#description' => $this->t('This allows you to preset the number of slides visible with a particular browser width. The format is [x,y] whereby x=browser width and y=number of slides displayed. For example [1199,4] means that if(window<=1199){ show 4 slides per page}'), '#default_value' => $this->options['itemsDesktop']);
$form['itemsDesktopSmall'] = array('#type' => 'textfield', '#title' => $this->t('Items Desktop Small'), '#description' => $this->t('Example: [979,3]'), '#default_value' => $this->options['itemsDesktopSmall']);
$form['itemsTablet'] = array('#type' => 'textfield', '#title' => $this->t('Items Tablet'), '#description' => $this->t('Example: [768,2]'), '#default_value' => $this->options['itemsTablet']);
$form['itemsMobile'] = array('#type' => 'textfield', '#title' => $this->t('Items Mobile'), '#description' => $this->t('Example: [479,1]'), '#default_value' => $this->options['itemsMobile']);
$form['singleItem'] = array('#type' => 'checkbox', '#title' => $this->t('Single Item'), '#default_value' => $this->options['singleItem'], '#description' => $this->t('Display only one item.'));
//itemsScaleUp
$form['itemsScaleUp'] = array('#type' => 'checkbox', '#title' => $this->t('Items ScaleUp'), '#default_value' => $this->options['itemsScaleUp'], '#description' => $this->t('Option to not stretch items when it is less than the supplied items.'));
//slideSpeed
$form['slideSpeed'] = array('#type' => 'number', '#title' => $this->t('Slide Speed'), '#default_value' => $this->options['slideSpeed'], '#description' => $this->t('Slide speed in milliseconds.'));
//paginationSpeed
$form['paginationSpeed'] = array('#type' => 'number', '#title' => $this->t('Pagination Speed'), '#default_value' => $this->options['paginationSpeed'], '#description' => $this->t('Pagination speed in milliseconds.'));
//rewindSpeed
$form['rewindSpeed'] = array('#type' => 'number', '#title' => $this->t('Rewind Speed'), '#default_value' => $this->options['rewindSpeed'], '#description' => $this->t('Rewind speed in milliseconds.'));
//autoPlay
$form['autoPlay'] = array('#type' => 'checkbox', '#title' => $this->t('AutoPlay'), '#default_value' => $this->options['autoPlay']);
//stopOnHover
$form['stopOnHover'] = array('#type' => 'checkbox', '#title' => $this->t('Stop On Hover'), '#default_value' => $this->options['stopOnHover'], '#description' => $this->t('Stop autoplay on mouse hover.'));
//navigation
$form['navigation'] = array('#type' => 'checkbox', '#title' => $this->t('Navigation'), '#default_value' => $this->options['navigation'], '#description' => $this->t('Display "next" and "prev" buttons.'));
//prevText
$form['prevText'] = array('#type' => 'textfield', '#title' => $this->t('Prev Text'), '#default_value' => $this->options['prevText'], '#description' => $this->t('Text for navigation prev button'));
//nextText
$form['nextText'] = array('#type' => 'textfield', '#title' => $this->t('Next Text'), '#default_value' => $this->options['nextText'], '#description' => $this->t('Text for navigation next button'));
//rewindNav
$form['rewindNav'] = array('#type' => 'checkbox', '#title' => $this->t('Rewind Nav'), '#default_value' => $this->options['rewindNav'], '#description' => $this->t('Slide to first item.'));
//scrollPerPage
$form['scrollPerPage'] = array('#type' => 'checkbox', '#title' => $this->t('Scroll Per Page'), '#default_value' => $this->options['scrollPerPage'], '#description' => $this->t('Scroll per page not per item. This affect next/prev buttons and mouse/touch dragging.'));
//pagination
$form['pagination'] = array('#type' => 'checkbox', '#title' => $this->t('pagination'), '#default_value' => $this->options['pagination'], '#description' => $this->t('Show pagination.'));
//paginationNumbers
$form['paginationNumbers'] = array('#type' => 'checkbox', '#title' => $this->t('Pagination Numbers'), '#default_value' => $this->options['paginationNumbers'], '#description' => $this->t('Show numbers inside pagination buttons.'));
//responsive
$form['responsive'] = array('#type' => 'checkbox', '#title' => $this->t('Responsive'), '#default_value' => $this->options['responsive'], '#description' => $this->t('Uncheck to use Owl Carousel on desktop-only.'));
//responsiveRefreshRate
$form['responsiveRefreshRate'] = array('#type' => 'number', '#title' => $this->t('Responsive Refresh Rate'), '#default_value' => $this->options['responsiveRefreshRate'], '#description' => $this->t('Check window width changes every 200ms for responsive actions.'));
//mouseDrag
$form['mouseDrag'] = array('#type' => 'checkbox', '#title' => $this->t('Mouse Drag'), '#default_value' => $this->options['mouseDrag'], '#description' => $this->t('Turn off/on mouse events.'));
//touchDrag
$form['touchDrag'] = array('#type' => 'checkbox', '#title' => $this->t('Touch Drag'), '#default_value' => $this->options['touchDrag'], '#description' => $this->t('Turn off/on touch events.'));
//transitionStyle
$form['transitionStyle'] = array('#type' => 'select', '#options' => array('fade' => $this->t('Fade'), 'backSlide' => $this->t('Back Slide'), 'goDown' => $this->t('Go Down'), 'scaleUp' => $this->t('ScaleUp')), '#title' => $this->t('Transition Style'), '#default_value' => $this->options['transitionStyle'], '#description' => $this->t('Add CSS3 transition style. Works only with one item on screen.'));
}
示例12: buildOptionsForm
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
$form['columns'] = array('#type' => 'number', '#title' => $this->t('Number of columns'), '#default_value' => $this->options['columns'], '#required' => TRUE, '#min' => 1);
$form['automatic_width'] = array('#type' => 'checkbox', '#title' => $this->t('Automatic width'), '#description' => $this->t('The width of each column will be calculated automatically based on the number of columns provided. If additional classes are entered or a theme injects classes based on a grid system, disabling this option may prove beneficial.'), '#default_value' => $this->options['automatic_width']);
$form['alignment'] = array('#type' => 'radios', '#title' => $this->t('Alignment'), '#options' => array('horizontal' => $this->t('Horizontal'), 'vertical' => $this->t('Vertical')), '#default_value' => $this->options['alignment'], '#description' => $this->t('Horizontal alignment will place items starting in the upper left and moving right. Vertical alignment will place items starting in the upper left and moving down.'));
$form['col_class_default'] = array('#title' => $this->t('Default column classes'), '#description' => $this->t('Add the default views column classes like views-col, col-1 and clearfix to the output. You can use this to quickly reduce the amount of markup the view provides by default, at the cost of making it more difficult to apply CSS.'), '#type' => 'checkbox', '#default_value' => $this->options['col_class_default']);
$form['col_class_custom'] = array('#title' => $this->t('Custom column class'), '#description' => $this->t('Additional classes to provide on each column. Separated by a space.'), '#type' => 'textfield', '#default_value' => $this->options['col_class_custom']);
if ($this->usesFields()) {
$form['col_class_custom']['#description'] .= ' ' . $this->t('You may use field tokens from as per the "Replacement patterns" used in "Rewrite the output of this field" for all fields.');
}
$form['row_class_default'] = array('#title' => $this->t('Default row classes'), '#description' => $this->t('Adds the default views row classes like views-row, row-1 and clearfix to the output. You can use this to quickly reduce the amount of markup the view provides by default, at the cost of making it more difficult to apply CSS.'), '#type' => 'checkbox', '#default_value' => $this->options['row_class_default']);
$form['row_class_custom'] = array('#title' => $this->t('Custom row class'), '#description' => $this->t('Additional classes to provide on each row. Separated by a space.'), '#type' => 'textfield', '#default_value' => $this->options['row_class_custom']);
if ($this->usesFields()) {
$form['row_class_custom']['#description'] .= ' ' . $this->t('You may use field tokens from as per the "Replacement patterns" used in "Rewrite the output of this field" for all fields.');
}
}
示例13: buildOptionsForm
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
$form['mode'] = array('#prefix' => '<h4>bxSlider Settings</h4>', '#type' => 'select', '#title' => t('Mode'), '#description' => t('Type of transition between slides'), '#options' => array('horizontal' => t('Horizontal'), 'vertical' => t('Vertical'), 'fade' => t('Fade')), '#default_value' => $this->options['mode']);
$form['ticker'] = array('#type' => 'select', '#title' => t('Ticker Enabled'), '#description' => t('If yes, use slider in ticker mode (similar to a news ticker)'), '#options' => array(true => 'Yes', false => 'No'), '#default_value' => $this->options['ticker']);
$form['tickerHover'] = array('#type' => 'select', '#title' => t('Ticker Hover'), '#description' => t('Ticker will pause when mouse hovers over slider. Note: this functionality does NOT work if using CSS transitions!'), '#options' => array(true => 'Yes', false => 'No'), '#default_value' => $this->options['tickerHover']);
$form['speed'] = array('#type' => 'textfield', '#title' => t('Speed'), '#description' => t('Slide transition duration (in ms)'), '#default_value' => $this->options['speed']);
$form['touchEnabled'] = array('#type' => 'select', '#title' => t('Touch Enabled'), '#description' => t('If yes, slider will allow touch swipe transitions'), '#options' => array(true => 'Yes', false => 'No'), '#default_value' => $this->options['touchEnabled']);
$form['auto'] = array('#type' => 'select', '#title' => t('Auto'), '#description' => t('Slides will automatically transition.'), '#options' => array(true => 'Yes', false => 'No'), '#default_value' => $this->options['auto']);
$form['pause'] = array('#type' => 'textfield', '#title' => t('Pause'), '#description' => t('The amount of time (in ms) between each auto transition.'), '#default_value' => $this->options['pause']);
$form['infiniteloop'] = array('#type' => 'select', '#title' => t('Infinite'), '#description' => t('If true, clicking "Next" while on the last slide will transition to the first slide and vice-versa'), '#options' => array(true => t('Yes'), false => t('No')), '#default_value' => $this->options['infiniteloop']);
$form['slidemargin'] = array('#type' => 'textfield', '#title' => t('Slide Margin'), '#description' => t('Margin between each slide'), '#default_value' => $this->options['slidemargin']);
$form['startslide'] = array('#type' => 'textfield', '#title' => t('Start Slide'), '#description' => t('Starting slide index (zero-based)'), '#default_value' => $this->options['startslide']);
$form['randomstart'] = array('#type' => 'select', '#title' => t('Random Start'), '#options' => array(true => t('Yes'), false => t('No')), '#description' => t('Start slider on a random slide'), '#default_value' => $this->options['randomstart']);
$form['pager'] = array('#type' => 'select', '#title' => t('Show Pager'), '#description' => t('If yes, a pager will be added.'), '#options' => array(true => 'Yes', false => 'No'), '#default_value' => $this->options['pager']);
$form['controls'] = array('#type' => 'select', '#title' => t('Show Controls'), '#description' => t('If yes, next/prev controls will be added.'), '#options' => array(true => 'Yes', false => 'No'), '#default_value' => $this->options['controls']);
$form['nexttext'] = array('#type' => 'textfield', '#title' => t('Custom nextText'), '#description' => t('Custom text to be used for the "Next" control'), '#default_value' => $this->options['nexttext']);
$form['prevtext'] = array('#type' => 'textfield', '#title' => t('Custom prevText'), '#description' => t('Custom text to be used for the "Prev" control'), '#default_value' => $this->options['prevtext']);
$form['autoControls'] = array('#type' => 'select', '#title' => t('Show Auto Controls'), '#description' => t('If Yes, "Start" / "Stop" controls will be added. Note: this functionality work if auto is true!'), '#options' => array(true => 'Yes', false => 'No'), '#default_value' => $this->options['autoControls']);
$form['moveslides'] = array('#type' => 'textfield', '#title' => t('Move Slides'), '#description' => t('The number of slides to move on transition. This value must be >= minSlides, and <= maxSlides. If zero (default), the number of fully-visible slides will be used.'), '#default_value' => $this->options['moveslides']);
$form['lg_items'] = array('#type' => 'select', '#title' => t('Large Desktop Items'), '#description' => t('Number of items on large desktop'), '#options' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12), '#default_value' => $this->options['lg_items']);
$form['md_items'] = array('#type' => 'select', '#title' => t('Desktop Items'), '#description' => t('Number of items on desktop'), '#options' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12), '#default_value' => $this->options['md_items']);
$form['sm_items'] = array('#type' => 'select', '#title' => t('Tablet Items'), '#description' => t('Number of items on tablet'), '#options' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12), '#default_value' => $this->options['sm_items']);
$form['xs_items'] = array('#type' => 'select', '#title' => t('Phone Items'), '#description' => t('Number of items on phone'), '#options' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12), '#default_value' => $this->options['xs_items']);
}
示例14: buildOptionsForm
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
// Wrap all the form elements to help style the form.
$form['views_slideshow_wrapper'] = array('#markup' => '<div id="views-slideshow-form-wrapper">');
/**
* Style.
*/
$form['slideshow_skin_header'] = array('#markup' => '<h2>' . t('Style') . '</h2>');
// Get a list of all available skins.
$skin_info = $this->getSkins();
foreach ($skin_info as $skin => $info) {
$skins[$skin] = $info['name'];
}
asort($skins);
// Create the drop down box so users can choose an available skin.
$form['slideshow_skin'] = array('#type' => 'select', '#title' => t('Skin'), '#options' => $skins, '#default_value' => $this->options['slideshow_skin'], '#description' => t('Select the skin to use for this display. Skins allow for easily swappable layouts of things like next/prev links and thumbnails. Note that not all skins support all widgets, so a combination of skins and widgets may lead to unpredictable results in layout.'));
/**
* Slides
*/
$form['slides_header'] = array('#markup' => '<h2>' . t('Slides') . '</h2>');
// Get all slideshow types.
$slideshows = \Drupal::moduleHandler()->invokeAll('views_slideshow_slideshow_info');
if ($slideshows) {
// Build our slideshow options for the form.
$slideshow_options = array();
foreach ($slideshows as $slideshow_id => $slideshow_info) {
$slideshow_options[$slideshow_id] = $slideshow_info['name'];
}
$form['slideshow_type'] = array('#type' => 'select', '#title' => t('Slideshow Type'), '#options' => $slideshow_options, '#default_value' => $this->options['slideshow_type']);
$arguments = array(&$form, &$form_state, &$this);
foreach (\Drupal::moduleHandler()->getImplementations('views_slideshow_slideshow_type_form') as $module) {
$form[$module] = array('#type' => 'fieldset', '#title' => t('!module options', array('!module' => $slideshows[$module]['name'])), '#collapsible' => TRUE, '#attributes' => array('class' => array($module)), '#states' => array('visible' => array(':input[name="style_options[slideshow_type]"]' => array('value' => $module))));
$function = $module . '_views_slideshow_slideshow_type_form';
call_user_func_array($function, $arguments);
}
} else {
$form['enable_module'] = array('#markup' => t('There is no Views Slideshow plugin enabled. Go to the !modules and enable a Views Slideshow plugin module. For example Views Slideshow Singleframe.', array('!modules' => \Drupal::l(t('Modules Page'), Url::fromRoute('system.modules_list')))));
}
/**
* Widgets
*/
$form['widgets_header'] = array('#markup' => '<h2>' . t('Widgets') . '</h2>');
// Loop through all locations so we can add header for each location.
$location = array('top' => t('Top'), 'bottom' => t('Bottom'));
foreach ($location as $location_id => $location_name) {
// Widget Header
$form['widgets'][$location_id]['header'] = array('#markup' => '<h3>' . t('!location Widgets', array('!location' => $location_name)) . '</h3>');
}
// Get all widgets that are registered.
// If we have widgets then build it's form fields.
$widgets = \Drupal::moduleHandler()->invokeAll('views_slideshow_widget_info');
if (!empty($widgets)) {
// Build our weight values by number of widgets
$weights = array();
for ($i = 1; $i <= count($widgets); $i++) {
$weights[$i] = $i;
}
// Loop through our widgets and locations to build our form values for
// each widget.
foreach ($widgets as $widget_id => $widget_info) {
foreach ($location as $location_id => $location_name) {
$widget_dependency = 'style_options[widgets][' . $location_id . '][' . $widget_id . ']';
// Determine if a widget is compatible with a slideshow.
$compatible_slideshows = array();
foreach ($slideshows as $slideshow_id => $slideshow_info) {
$is_compatible = 1;
// Check if every required accept value in the widget has a
// corresponding calls value in the slideshow.
foreach ($widget_info['accepts'] as $accept_key => $accept_value) {
if (is_array($accept_value) && !empty($accept_value['required']) && !in_array($accept_key, $slideshow_info['calls'])) {
$is_compatible = 0;
break;
}
}
// No need to go through this if it's not compatible.
if ($is_compatible) {
// Check if every required calls value in the widget has a
// corresponding accepts call.
foreach ($widget_info['calls'] as $calls_key => $calls_value) {
if (is_array($calls_value) && !empty($calls_value['required']) && !in_array($calls_key, $slideshow_info['accepts'])) {
$is_compatible = 0;
break;
}
}
}
// If it passed all those tests then they are compatible.
if ($is_compatible) {
$compatible_slideshows[] = $slideshow_id;
}
}
// Use Widget Checkbox
$form['widgets'][$location_id][$widget_id]['enable'] = array('#type' => 'checkbox', '#title' => t($widget_info['name']), '#default_value' => $this->options['widgets'][$location_id][$widget_id]['enable'], '#description' => t('Should !name be rendered at the !location of the slides.', array('!name' => $widget_info['name'], '!location' => $location_name)));
$form['widgets'][$location_id][$widget_id]['enable']['#dependency']['edit-style-options-slideshow-type'] = !empty($compatible_slideshows) ? $compatible_slideshows : array('none');
// Need to wrap this so it indents correctly.
$form['widgets'][$location_id][$widget_id]['wrapper'] = array('#markup' => '<div class="vs-dependent">');
// Widget weight
//.........这里部分代码省略.........
示例15: buildOptionsForm
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
$labels = $this->displayHandler->getFieldLabels();
$fieldMap = \Drupal::entityManager()->getFieldMap();
$geo_options = [];
$title_options = [];
$filters = $this->displayHandler->getOption('filters');
$fields = $this->displayHandler->getOption('fields');
foreach ($fields as $field_name => $field) {
if ($field['plugin_id'] == 'geolocation_field') {
$geo_options[$field_name] = $labels[$field_name];
}
if ($field['plugin_id'] == 'field' && !empty($field['entity_type']) && !empty($field['entity_field'])) {
if (!empty($fieldMap[$field['entity_type']][$field['entity_field']]['type']) && $fieldMap[$field['entity_type']][$field['entity_field']]['type'] == 'geolocation') {
$geo_options[$field_name] = $labels[$field_name];
}
}
if ($field['type'] == 'string') {
$title_options[$field_name] = $labels[$field_name];
}
}
$form['geolocation_field'] = ['#title' => $this->t('Geolocation source field'), '#type' => 'select', '#default_value' => $this->options['geolocation_field'], '#description' => $this->t("The source of geodata for each entity."), '#options' => $geo_options];
$form['title_field'] = ['#title' => $this->t('Title source field'), '#type' => 'select', '#default_value' => $this->options['title_field'], '#description' => $this->t("The source of the title for each entity. Must be string"), '#options' => $title_options];
$options = ['first_row' => $this->t('Use first row as centre.'), 'fixed_value' => $this->t('Provide fixed latitude and longitude.')];
foreach ($filters as $filter_name => $filter) {
if (empty($filter['plugin_id']) || $filter['plugin_id'] != 'geolocation_filter_proximity') {
continue;
}
$options['proximity_filter_' . $filter_name] = $this->displayHandler->getHandler('filter', $filter_name)->adminLabel();
}
$form['centre'] = ['#type' => 'table', '#header' => [t('Enable'), t('Option'), t('settings'), array('data' => t('Settings'), 'colspan' => '1')], '#attributes' => ['id' => 'geolocation-centre-options'], '#tabledrag' => [['action' => 'order', 'relationship' => 'sibling', 'group' => 'geolocation-centre-option-weight']]];
foreach ($options as $id => $label) {
$weight = $this->options['centre'][$id]['weight'] ?: 0;
$form['centre'][$id]['#weight'] = $weight;
$form['centre'][$id]['enable'] = ['#type' => 'checkbox', '#default_value' => isset($this->options['centre'][$id]['enable']) ? $this->options['centre'][$id]['enable'] : TRUE];
$form['centre'][$id]['option'] = ['#markup' => $label];
// Optionally, to add tableDrag support:
$form['centre'][$id]['#attributes']['class'][] = 'draggable';
$form['centre'][$id]['weight'] = ['#type' => 'weight', '#title' => t('Weight for @option', ['@option' => $label]), '#title_display' => 'invisible', '#size' => 4, '#default_value' => $weight, '#attributes' => ['class' => ['geolocation-centre-option-weight']]];
}
$form['centre']['fixed_value']['settings'] = ['#title' => $this->t('Fixed values for centre'), '#type' => 'container', 'latitude' => ['#type' => 'textfield', '#title' => t('Latitude'), '#default_value' => $this->options['centre']['fixed_value']['settings']['latitude'], '#size' => 60, '#maxlength' => 128], 'longitude' => ['#type' => 'textfield', '#title' => t('Longitude'), '#default_value' => $this->options['centre']['fixed_value']['settings']['longitude'], '#size' => 60, '#maxlength' => 128], '#description' => $this->t("The source of geodata for each entity. Must be string"), '#states' => ['visible' => [':input[name="style_options[centre][fixed_value][enable]"]' => ['checked' => TRUE]]]];
uasort($form['centre'], 'Drupal\\Component\\Utility\\SortArray::sortByWeightProperty');
}