Example #1
3
/**
 * Preprocess input.
 */
function bootstrap_preprocess_input(&$variables)
{
    $element =& $variables['element'];
    $attributes = new Attribute($variables['attributes']);
    // Set the element's attributes.
    \Drupal\Core\Render\Element::setAttributes($element, array('id', 'name', 'value', 'type'));
    // Handle button inputs.
    if (_bootstrap_is_button($element)) {
        $variables['attributes']['class'][] = 'btn';
        _bootstrap_colorize_button($variables);
        _bootstrap_iconize_button($element);
        // Add button size, if necessary.
        if ($size = bootstrap_setting('button_size')) {
            $variables['attributes']['class'][] = $size;
        }
        // Add in the button type class.
        $variables['attributes']['class'][] = 'form-' . $element['#type'];
        $variables['label'] = $element['#value'];
    }
    _bootstrap_prerender_input($variables);
    // Autocomplete fields.
    if (!empty($element['#autocomplete_route_name']) && Drupal::PathValidator($element['#autocomplete_route_name'])) {
        $variables['autocomplete'] = TRUE;
        // Attributes for hidden input field.
        $autocomplete_attributes = new Attribute();
        $autocomplete_attributes['type'] = 'hidden';
        $autocomplete_attributes['id'] = $element['#attributes']['id'] . '-autocomplete';
        $autocomplete_attributes['value'] = Drupal::Url($element['#autocomplete_route_name'], $element['#autocomplete_route_parameters']);
        $autocomplete_attributes['disabled'] = 'disabled';
        $autocomplete_attributes['class'] = 'autocomplete';
        // Uses icon for autocomplete "throbber".
        $icon = _bootstrap_icon('refresh');
        // Fallback to using core's throbber.
        if (empty($icon)) {
            $icon = array('#type' => 'container', '#attributes' => array('class' => array('ajax-progress', 'ajax-progress-throbber', 'invisible')), 'throbber' => array('#type' => 'html_tag', '#tag' => 'div', '#attributes' => array('class' => array('throbber'))));
        }
        $variables['autocomplete_icon'] = $icon;
        $variables['autocomplete_attributes'] = $autocomplete_attributes;
    }
    // Search fields.
    if ($element['#type'] == 'search') {
        $attributes['placeholder'] = t('Search');
        $attributes['data-original-title'] = t('Enter the terms you wish to search for.');
    }
    // Additional Twig variables.
    $variables['icon'] = $element['#icon'];
    $variables['element'] = $element;
}
Example #2
0
 /**
  * Tests default and custom block categories.
  */
 public function testBlockCategory()
 {
     $this->drupalLogin($this->drupalCreateUser(array('administer views', 'administer blocks')));
     // Create a new view in the UI.
     $edit = array();
     $edit['label'] = $this->randomString();
     $edit['id'] = strtolower($this->randomMachineName());
     $edit['show[wizard_key]'] = 'standard:views_test_data';
     $edit['description'] = $this->randomString();
     $edit['block[create]'] = TRUE;
     $edit['block[style][row_plugin]'] = 'fields';
     $this->drupalPostForm('admin/structure/views/add', $edit, t('Save and edit'));
     $pattern = '//tr[.//td[text()=:category] and .//td//a[contains(@href, :href)]]';
     // Test that the block was given a default category corresponding to its
     // base table.
     $arguments = array(':href' => \Drupal::Url('block.admin_add', array('plugin_id' => 'views_block:' . $edit['id'] . '-block_1', 'theme' => 'classy')), ':category' => t('Lists (Views)'));
     $this->drupalGet('admin/structure/block');
     $this->clickLinkPartialName('Place block');
     $elements = $this->xpath($pattern, $arguments);
     $this->assertTrue(!empty($elements), 'The test block appears in the category for its base table.');
     // Duplicate the block before changing the category.
     $this->drupalPostForm('admin/structure/views/view/' . $edit['id'] . '/edit/block_1', array(), t('Duplicate @display_title', array('@display_title' => 'Block')));
     $this->assertUrl('admin/structure/views/view/' . $edit['id'] . '/edit/block_2');
     // Change the block category to a random string.
     $this->drupalGet('admin/structure/views/view/' . $edit['id'] . '/edit/block_1');
     $link = $this->xpath('//a[@id="views-block-1-block-category" and normalize-space(text())=:category]', $arguments);
     $this->assertTrue(!empty($link));
     $this->clickLink(t('Lists (Views)'));
     $category = $this->randomString();
     $this->drupalPostForm(NULL, array('block_category' => $category), t('Apply'));
     // Duplicate the block after changing the category.
     $this->drupalPostForm(NULL, array(), t('Duplicate @display_title', array('@display_title' => 'Block')));
     $this->assertUrl('admin/structure/views/view/' . $edit['id'] . '/edit/block_3');
     $this->drupalPostForm(NULL, array(), t('Save'));
     // Test that the blocks are listed under the correct categories.
     $arguments[':category'] = $category;
     $this->drupalGet('admin/structure/block');
     $this->clickLinkPartialName('Place block');
     $elements = $this->xpath($pattern, $arguments);
     $this->assertTrue(!empty($elements), 'The test block appears in the custom category.');
     $arguments = array(':href' => \Drupal::Url('block.admin_add', array('plugin_id' => 'views_block:' . $edit['id'] . '-block_2', 'theme' => 'classy')), ':category' => t('Lists (Views)'));
     $elements = $this->xpath($pattern, $arguments);
     $this->assertTrue(!empty($elements), 'The first duplicated test block remains in the original category.');
     $arguments = array(':href' => \Drupal::Url('block.admin_add', array('plugin_id' => 'views_block:' . $edit['id'] . '-block_3', 'theme' => 'classy')), ':category' => $category);
     $elements = $this->xpath($pattern, $arguments);
     $this->assertTrue(!empty($elements), 'The second duplicated test block appears in the custom category.');
 }
Example #3
0
 /**
  * Tests default and custom block categories.
  */
 public function testBlockCategory()
 {
     $this->drupalLogin($this->drupalCreateUser(array('administer views', 'administer blocks')));
     // Create a new view in the UI.
     $edit = array();
     $edit['label'] = $this->randomString();
     $edit['id'] = strtolower($this->randomName());
     $edit['show[wizard_key]'] = 'standard:views_test_data';
     $edit['description'] = $this->randomString();
     $edit['block[create]'] = TRUE;
     $edit['block[style][row_plugin]'] = 'fields';
     $this->drupalPostForm('admin/structure/views/add', $edit, t('Save and edit'));
     // Test that the block was given a default category corresponding to its
     // base table.
     $arguments = array(':id' => 'edit-category-lists-views', ':li_class' => 'views-block' . drupal_html_class($edit['id']) . '-block-1', ':href' => \Drupal::Url('block.admin_add', array('plugin_id' => 'views_block:' . $edit['id'] . '-block_1', 'theme' => 'stark')), ':text' => $edit['label']);
     $this->drupalGet('admin/structure/block');
     $elements = $this->xpath('//details[@id=:id]//li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $arguments);
     $this->assertTrue(!empty($elements), 'The test block appears in the category for its base table.');
     // Duplicate the block before changing the category.
     $this->drupalPostForm('admin/structure/views/view/' . $edit['id'] . '/edit/block_1', array(), t('Duplicate @display_title', array('@display_title' => 'Block')));
     $this->assertUrl('admin/structure/views/view/' . $edit['id'] . '/edit/block_2');
     // Change the block category to a random string.
     $this->drupalGet('admin/structure/views/view/' . $edit['id'] . '/edit/block_1');
     $label = t('Lists (Views)');
     $link = $this->xpath('//a[@id="views-block-1-block-category" and normalize-space(text())=:label]', array(':label' => $label));
     $this->assertTrue(!empty($link));
     $this->clickLink($label);
     $category = $this->randomString();
     $this->drupalPostForm(NULL, array('block_category' => $category), t('Apply'));
     // Duplicate the block after changing the category.
     $this->drupalPostForm(NULL, array(), t('Duplicate @display_title', array('@display_title' => 'Block')));
     $this->assertUrl('admin/structure/views/view/' . $edit['id'] . '/edit/block_3');
     $this->drupalPostForm(NULL, array(), t('Save'));
     // Test that the blocks are listed under the correct categories.
     $category_id = drupal_html_id('edit-category-' . String::checkPlain($category));
     $arguments[':id'] = $category_id;
     $this->drupalGet('admin/structure/block');
     $elements = $this->xpath('//details[@id=:id]//li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $arguments);
     $this->assertTrue(!empty($elements), 'The test block appears in the custom category.');
     $arguments = array(':id' => 'edit-category-lists-views', ':li_class' => 'views-block' . drupal_html_class($edit['id']) . '-block-2', ':href' => \Drupal::Url('block.admin_add', array('plugin_id' => 'views_block:' . $edit['id'] . '-block_2', 'theme' => 'stark')), ':text' => $edit['label']);
     $elements = $this->xpath('//details[@id=:id]//li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $arguments);
     $this->assertTrue(!empty($elements), 'The first duplicated test block remains in the original category.');
     $arguments = array(':id' => $category_id, ':li_class' => 'views-block' . drupal_html_class($edit['id']) . '-block-3', ':href' => \Drupal::Url('block.admin_add', array('plugin_id' => 'views_block:' . $edit['id'] . '-block_3', 'theme' => 'stark')), ':text' => $edit['label']);
     $elements = $this->xpath('//details[@id=:id]//li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $arguments);
     $this->assertTrue(!empty($elements), 'The second duplicated test block appears in the custom category.');
 }