views_ui_truncate example



    if ($this->display['id'] != 'default') {
      $options['display_id'] = [
        'category' => 'other',
        'title' => $this->t('Machine Name'),
        'value' => !empty($this->display['new_id']) ? $this->display['new_id'] : $this->display['id'],
        'desc' => $this->t('Change the machine name of this display.'),
      ];
    }

    $display_comment = views_ui_truncate($this->getOption('display_comment'), 80);
    $options['display_comment'] = [
      'category' => 'other',
      'title' => $this->t('Administrative comment'),
      'value' => !empty($display_comment) ? $display_comment : $this->t('None'),
      'desc' => $this->t('Comment or document this display.'),
    ];

    $title = strip_tags($this->getOption('title'));
    if (!$title) {
      $title = $this->t('None');
    }

    
'column' => 'second',
      'build' => [
        '#weight' => -10,
      ],
    ];

    $options['path']['category'] = 'path';
    $options['path']['title'] = $this->t('Path');
    $options['auth'] = [
      'category' => 'path',
      'title' => $this->t('Authentication'),
      'value' => views_ui_truncate($auth, 24),
    ];

    // Remove css/exposed form settings, as they are not used for the data     // display.     unset($options['exposed_form']);
    unset($options['exposed_block']);
    unset($options['css_class']);
  }

  /** * {@inheritdoc} */


    $block_description = strip_tags($this->getOption('block_description'));
    if (empty($block_description)) {
      $block_description = $this->t('None');
    }
    $block_category = $this->getOption('block_category');

    $options['block_description'] = [
      'category' => 'block',
      'title' => $this->t('Block name'),
      'value' => views_ui_truncate($block_description, 24),
    ];
    $options['block_category'] = [
      'category' => 'block',
      'title' => $this->t('Block category'),
      'value' => views_ui_truncate($block_category, 24),
    ];

    $filtered_allow = array_filter($this->getOption('allow'));

    $options['allow'] = [
      'category' => 'block',
      
return $advanced_mode || $additional_displays;
  }

  /** * Placeholder function for overriding $display['display_title']. * * @todo Remove this function once editing the display title is possible. */
  public function getDisplayLabel(ViewUI $view$display_id$check_changed = TRUE) {
    $display = $view->get('display');
    $title = $display_id == 'default' ? $this->t('Default') : $display[$display_id]['display_title'];
    $title = views_ui_truncate($title, 25);

    if ($check_changed && !empty($view->changed_display[$display_id])) {
      $changed = '*';
      $title = $title . $changed;
    }

    return $title;
  }

}
$categories['display_extender_test'] = [
      'title' => $this->t('Display extender test settings'),
      'column' => 'second',
      'build' => [
        '#weight' => -100,
      ],
    ];

    $options['test_extender_test_option'] = [
      'category' => 'display_extender_test',
      'title' => $this->t('Test option'),
      'value' => views_ui_truncate($this->options['test_extender_test_option'], 24),
    ];
  }

  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    switch ($form_state->get('section')) {
      case 'test_extender_test_option':
        $form['#title'] .= $this->t('Test option');
        $form['test_extender_test_option'] = [
          
$view['block[create]'] = TRUE;
    $view['block[title]'] = $this->randomMachineName(255);
    $view['rest_export[create]'] = TRUE;
    $view['rest_export[path]'] = $this->randomMachineName(254);

    // Make sure the view saving was successful and the browser got redirected     // to the edit page.     $this->drupalGet('admin/structure/views/add');
    $this->submitForm($view, 'Save and edit');
    $this->assertSession()->addressEquals('admin/structure/views/view/' . $view['id']);
    // Assert that the page title is correctly truncated.     $this->assertSession()->pageTextContains(views_ui_truncate($view['page[title]'], 32));
  }

}
if (empty($path)) {
      $path = $this->t('No path is set');
    }
    else {
      $path = '/' . $path;
    }

    $options['path'] = [
      'category' => 'page',
      'title' => $this->t('Path'),
      'value' => views_ui_truncate($path, 24),
    ];
  }

  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);

    switch ($form_state->get('section')) {
      case 'path':
        
'column' => 'second',
      'build' => [
        '#weight' => -100,
      ],
    ];

    $test_option = $this->getOption('test_option') ?: $this->t('Empty');

    $options['test_option'] = [
      'category' => 'display_test',
      'title' => $this->t('Test option'),
      'value' => views_ui_truncate($test_option, 24),
    ];
  }

  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);

    switch ($form_state->get('section')) {
      case 'test_option':
        
$xss_markup = '"><script>alert(123)</script>';
    $view = $this->randomView();
    $view = View::load($view['id']);
    \Drupal::configFactory()->getEditable('views.settings')->set('ui.show.default_display', TRUE)->save();

    foreach ([$xss_markup, '&quot;><script>alert(123)</script>'] as $input) {
      $display =& $view->getDisplay('page_1');
      $display['display_title'] = $input;
      $view->save();

      $this->drupalGet("admin/structure/views/view/{$view->id()}");
      $escaped = views_ui_truncate($input, 25);
      $this->assertSession()->assertEscaped($escaped);
      $this->assertSession()->responseNotContains($xss_markup);

      $this->drupalGet("admin/structure/views/view/{$view->id()}/edit/page_1");
      $this->assertSession()->assertEscaped("View $escaped");
      $this->assertSession()->responseNotContains("View $xss_markup");
      $this->assertSession()->assertEscaped("Duplicate $escaped");
      $this->assertSession()->responseNotContains("Duplicate $xss_markup");
      $this->assertSession()->assertEscaped("Delete $escaped");
      $this->assertSession()->responseNotContains("Delete $xss_markup");
    }
  }
break;

      case 'tab':
      case 'default tab':
        $menu_str = $this->t('Tab: @title', ['@title' => $menu['title']]);
        break;
    }

    $options['menu'] = [
      'category' => 'page',
      'title' => $this->t('Menu'),
      'value' => views_ui_truncate($menu_str, 24),
    ];

    // This adds a 'Settings' link to the style_options setting if the style     // has options.     if ($menu['type'] == 'default tab') {
      $options['menu']['setting'] = $this->t('Parent menu link');
      $options['menu']['links']['tab_options'] = $this->t('Change settings for the parent menu');
    }

    // If the display path starts with 'admin/' the page will be rendered with     // the Administration theme regardless of the 'use_admin_theme' option
Home | Imprint | This part of the site doesn't use cookies.