getStyle example

$entity = EntityTestMul::create([
      'field_test' => [2, 2, 2],
    ]);
    $entity->save();
    $entities[] = $entity;

    $view = Views::getView('test_group_by_count_multicardinality');
    $this->executeView($view);
    $this->assertCount(2, $view->result);

    $this->assertEquals('3', $view->getStyle()->getField(0, 'id'));
    $this->assertEquals('1', $view->getStyle()->getField(0, 'field_test'));
    $this->assertEquals('6', $view->getStyle()->getField(1, 'id'));
    $this->assertEquals('2', $view->getStyle()->getField(1, 'field_test'));

    $entities[2]->field_test[0]->value = 3;
    $entities[2]->field_test[1]->value = 4;
    $entities[2]->field_test[2]->value = 5;
    $entities[2]->save();

    $view = Views::getView('test_group_by_count_multicardinality');
    $this->executeView($view);
    
$entity = EntityTestMul::create([
      'name' => 'name3',
    ]);
    $entity->field_data_test_unlimited->target_id = $entities[0]->id();
    $entity->save();

    $view = Views::getView('test_entity_reference_group_by_empty_relationships');
    $this->executeView($view);
    $this->assertCount(4, $view->result);
    // First three results should contain a reference from EntityTestMul.     $this->assertNotEmpty($view->getStyle()->getField(0, 'name_2'));
    $this->assertNotEmpty($view->getStyle()->getField(1, 'name_2'));
    $this->assertNotEmpty($view->getStyle()->getField(2, 'name_2'));
    // Fourth result has no reference from EntityTestMul hence the output for     // should be empty.     $this->assertEquals('', $view->getStyle()->getField(3, 'name_2'));

    $fields = $view->field;
    // Check getValue for reference with a value. The first 3 rows reference     // EntityTestMul, so have value 'name1'.     $this->assertEquals('name1', $fields['name_2']->getValue($view->result[0]));
    $this->assertEquals('name1', $fields['name_2']->getValue($view->result[1]));
    

    public function testFormat()
    {
        $formatter = new NullOutputFormatter();

        $this->assertNull($formatter->format('this message will be destroyed'));
    }

    public function testGetStyle()
    {
        $formatter = new NullOutputFormatter();
        $this->assertInstanceof(NullOutputFormatterStyle::class$style = $formatter->getStyle('null'));
        $this->assertSame($style$formatter->getStyle('null'));
    }

    public function testSetStyle()
    {
        $formatter = new NullOutputFormatter();
        $style = new OutputFormatterStyle();
        $formatter->setStyle('null', $style);
        $this->assertNotSame($style$formatter->getStyle('null'));
    }

    

  public function tokenizeValue($value) {
    if ($this->options['tokenize']) {
      $value = $this->view->getStyle()->tokenizeValue($value, 0);
    }
    // As we add the globalTokenForm() we also should replace the token here.     return $this->globalTokenReplace($value);
  }

}

  public function useStringGroupBy() {
    return TRUE;
  }

  protected function defineOptions() {
    $options = parent::defineOptions();

    $options['label'] = ['default' => ''];
    // Some styles (for example table) should have labels enabled by default.     $style = $this->view->getStyle();
    if (isset($style) && $style->defaultFieldLabels()) {
      $options['label']['default'] = $this->definition['title'];
    }

    $options['exclude'] = ['default' => FALSE];
    $options['alter'] = [
      'contains' => [
        'alter_text' => ['default' => FALSE],
        'text' => ['default' => ''],
        'make_link' => ['default' => FALSE],
        'path' => ['default' => ''],
        
'id' => 'id', 'field_test' => 'field_test', 'user_id' => 'user_id']
    );
  }

  /** * Tests the output of a view with base fields and configurable fields. */
  public function testSimpleRender() {
    $executable = Views::getView('test_field_field_test');
    $executable->execute();

    $this->assertEquals('1', $executable->getStyle()->getField(0, 'id'));
    $this->assertEquals('3', $executable->getStyle()->getField(0, 'field_test'));
    $this->assertEquals('2', $executable->getStyle()->getField(1, 'id'));
    // @todo Switch this assertion to assertSame('', ...) when     // https://www.drupal.org/node/2488006 gets fixed.     $this->assertEquals('0', $executable->getStyle()->getField(1, 'field_test'));
    $this->assertEquals('3', $executable->getStyle()->getField(2, 'id'));
    $this->assertEquals('8', $executable->getStyle()->getField(2, 'field_test'));
    $this->assertEquals('4', $executable->getStyle()->getField(3, 'id'));
    $this->assertEquals('5', $executable->getStyle()->getField(3, 'field_test'));
    $this->assertEquals('5', $executable->getStyle()->getField(4, 'id'));
    $this->assertEquals('6', $executable->getStyle()->getField(4, 'field_test'));
  }
return $this;
    }

    /** * Gets the current style for a column. * * If style was not set, it returns the global table style. */
    public function getColumnStyle(int $columnIndex): TableStyle
    {
        return $this->columnStyles[$columnIndex] ?? $this->getStyle();
    }

    /** * Sets the minimum width of a column. * * @return $this */
    public function setColumnWidth(int $columnIndex, int $width)static
    {
        $this->columnWidths[$columnIndex] = $width;

        
$this->assertEquals($view_hashspl_object_hash($view->query->view));
    $this->assertEquals($display_hashspl_object_hash($view->query->displayHandler));

    $view->destroy();

    // Test the plugin get methods.     $display_plugin = $view->getDisplay();
    $this->assertInstanceOf(DefaultDisplay::class$display_plugin);
    $this->assertInstanceOf(DefaultDisplay::class$view->display_handler);
    $this->assertSame($display_plugin$view->getDisplay(), 'The same display plugin instance was returned.');

    $style_plugin = $view->getStyle();
    $this->assertInstanceOf(DefaultStyle::class$style_plugin);
    $this->assertInstanceOf(DefaultStyle::class$view->style_plugin);
    $this->assertSame($style_plugin$view->getStyle(), 'The same style plugin instance was returned.');

    $pager_plugin = $view->getPager();
    $this->assertInstanceOf(PagerPluginBase::class$pager_plugin);
    $this->assertInstanceOf(PagerPluginBase::class$view->pager);
    $this->assertSame($pager_plugin$view->getPager(), 'The same pager plugin instance was returned.');

    $query_plugin = $view->getQuery();
    $this->assertInstanceOf(QueryPluginBase::class$query_plugin);
    
return $this;
    }

    /** * Gets the current style for a column. * * If style was not set, it returns the global table style. */
    public function getColumnStyle(int $columnIndex): TableStyle
    {
        return $this->columnStyles[$columnIndex] ?? $this->getStyle();
    }

    /** * Sets the minimum width of a column. * * @return $this */
    public function setColumnWidth(int $columnIndex, int $width)static
    {
        $this->columnWidths[$columnIndex] = $width;

        
$formatter->format('<error>error<info>info<comment>comment</info>error</error>')
        );
    }

    public function testNewStyle()
    {
        $formatter = new OutputFormatter(true);

        $style = new OutputFormatterStyle('blue', 'white');
        $formatter->setStyle('test', $style);

        $this->assertEquals($style$formatter->getStyle('test'));
        $this->assertNotEquals($style$formatter->getStyle('info'));

        $style = new OutputFormatterStyle('blue', 'white');
        $formatter->setStyle('b', $style);

        $this->assertEquals("\033[34;47msome \033[39;49m\033[34;47mcustom\033[39;49m\033[34;47m msg\033[39;49m", $formatter->format('<test>some <b>custom</b> msg</test>'));
    }

    public function testRedefineStyle()
    {
        $formatter = new OutputFormatter(true);

        
public function testTermNameField() {
    $this->term1->name->value = $this->randomMachineName() . ' ' . $this->randomMachineName();
    $this->term1->save();

    $user = $this->drupalCreateUser(['access content']);
    $this->drupalLogin($user);

    $view = Views::getView('test_taxonomy_term_name');
    $view->initDisplay();
    $this->executeView($view);

    $this->assertEquals($this->term1->getName()$view->getStyle()->getField(0, 'name'));
    $this->assertEquals($this->term2->getName()$view->getStyle()->getField(1, 'name'));

    $view = Views::getView('test_taxonomy_term_name');
    $display =& $view->storage->getDisplay('default');
    $display['display_options']['fields']['name']['convert_spaces'] = TRUE;
    $view->storage->invalidateCaches();
    $this->executeView($view);

    $this->assertEquals(str_replace(' ', '-', $this->term1->getName())$view->getStyle()->getField(0, 'name'));
    $this->assertEquals($this->term2->getName()$view->getStyle()->getField(1, 'name'));

    
Home | Imprint | This part of the site doesn't use cookies.