本文整理汇总了PHP中Drupal\views\Plugin\views\HandlerBase类的典型用法代码示例。如果您正苦于以下问题:PHP HandlerBase类的具体用法?PHP HandlerBase怎么用?PHP HandlerBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HandlerBase类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addTable
/**
* Add a table to the query.
*
* This is an advanced concept; not only does it add a new instance of the table,
* but it follows the relationship path all the way down to the relationship
* link point and adds *that* as a new relationship and then adds the table to
* the relationship, if necessary.
*/
public function addTable($join = NULL, $alias = NULL)
{
// This is used for lookups in the many_to_one table.
$field = $this->handler->relationship . '_' . $this->handler->table . '.' . $this->handler->field;
if (empty($join)) {
$join = $this->getJoin();
}
// See if there's a chain between us and the base relationship. If so, we need
// to create a new relationship to use.
$relationship = $this->handler->relationship;
// Determine the primary table to seek
if (empty($this->handler->query->relationships[$relationship])) {
$base_table = $this->handler->view->storage->get('base_table');
} else {
$base_table = $this->handler->query->relationships[$relationship]['base'];
}
// Cycle through the joins. This isn't as error-safe as the normal
// ensurePath logic. Perhaps it should be.
$r_join = clone $join;
while ($r_join->leftTable != $base_table) {
$r_join = HandlerBase::getTableJoin($r_join->leftTable, $base_table);
}
// If we found that there are tables in between, add the relationship.
if ($r_join->table != $join->table) {
$relationship = $this->handler->query->addRelationship($this->handler->table . '_' . $r_join->table, $r_join, $r_join->table, $this->handler->relationship);
}
// And now add our table, using the new relationship if one was used.
$alias = $this->handler->query->addTable($this->handler->table, $relationship, $join, $alias);
// Store what values are used by this table chain so that other chains can
// automatically discard those values.
if (empty($this->handler->view->many_to_one_tables[$field])) {
$this->handler->view->many_to_one_tables[$field] = $this->handler->value;
} else {
$this->handler->view->many_to_one_tables[$field] = array_merge($this->handler->view->many_to_one_tables[$field], $this->handler->value);
}
return $alias;
}
示例2: getJoinData
/**
* Retrieve join data from the larger join data cache.
*
* @param $table
* The table to get the join information for.
* @param $base_table
* The path we're following to get this join.
*
* @return \Drupal\views\Plugin\views\join\JoinPluginBase
* A Join object or child object, if one exists.
*/
public function getJoinData($table, $base_table) {
// Check to see if we're linking to a known alias. If so, get the real
// table's data instead.
if (!empty($this->tableQueue[$table])) {
$table = $this->tableQueue[$table]['table'];
}
return HandlerBase::getTableJoin($table, $base_table);
}
示例3: testBreakString
/**
* Tests the breakString method.
*/
public function testBreakString()
{
// Check defaults.
$this->assertEqual((object) array('value' => array(), 'operator' => NULL), HandlerBase::breakString(''));
// Test ors
$handler = HandlerBase::breakString('word1 word2+word');
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
$this->assertEqual('or', $handler->operator);
$handler = HandlerBase::breakString('word1+word2+word');
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
$this->assertEqual('or', $handler->operator);
$handler = HandlerBase::breakString('word1 word2 word');
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
$this->assertEqual('or', $handler->operator);
$handler = HandlerBase::breakString('word-1+word-2+word');
$this->assertEqualValue(array('word-1', 'word-2', 'word'), $handler);
$this->assertEqual('or', $handler->operator);
$handler = HandlerBase::breakString('wõrd1+wõrd2+wõrd');
$this->assertEqualValue(array('wõrd1', 'wõrd2', 'wõrd'), $handler);
$this->assertEqual('or', $handler->operator);
// Test ands.
$handler = HandlerBase::breakString('word1,word2,word');
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
$this->assertEqual('and', $handler->operator);
$handler = HandlerBase::breakString('word1 word2,word');
$this->assertEqualValue(array('word1 word2', 'word'), $handler);
$this->assertEqual('and', $handler->operator);
$handler = HandlerBase::breakString('word1,word2 word');
$this->assertEqualValue(array('word1', 'word2 word'), $handler);
$this->assertEqual('and', $handler->operator);
$handler = HandlerBase::breakString('word-1,word-2,word');
$this->assertEqualValue(array('word-1', 'word-2', 'word'), $handler);
$this->assertEqual('and', $handler->operator);
$handler = HandlerBase::breakString('wõrd1,wõrd2,wõrd');
$this->assertEqualValue(array('wõrd1', 'wõrd2', 'wõrd'), $handler);
$this->assertEqual('and', $handler->operator);
// Test a single word
$handler = HandlerBase::breakString('word');
$this->assertEqualValue(array('word'), $handler);
$this->assertEqual('and', $handler->operator);
$s1 = $this->randomMachineName();
// Generate three random numbers which can be used below;
$n1 = rand(0, 100);
$n2 = rand(0, 100);
$n3 = rand(0, 100);
// Test "or"s.
$handlerBase = HandlerBase::breakString("{$s1} {$n2}+{$n3}");
$this->assertEqualValue(array($s1, $n2, $n3), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
$handlerBase = HandlerBase::breakString("{$s1}+{$n2}+{$n3}");
$this->assertEqualValue(array($s1, $n2, $n3), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
$handlerBase = HandlerBase::breakString("{$s1} {$n2} {$n3}");
$this->assertEqualValue(array($s1, $n2, $n3), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
$handlerBase = HandlerBase::breakString("{$s1} {$n2}++{$n3}");
$this->assertEqualValue(array($s1, $n2, $n3), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
// Test "and"s.
$handlerBase = HandlerBase::breakString("{$s1},{$n2},{$n3}");
$this->assertEqualValue(array($s1, $n2, $n3), $handlerBase);
$this->assertEqual('and', $handlerBase->operator);
$handlerBase = HandlerBase::breakString("{$s1},,{$n2},{$n3}");
$this->assertEqualValue(array($s1, $n2, $n3), $handlerBase);
$this->assertEqual('and', $handlerBase->operator);
// Enforce int values.
$handlerBase = HandlerBase::breakString("{$n1},{$n2},{$n3}", TRUE);
$this->assertEqualValue(array($n1, $n2, $n3), $handlerBase);
$this->assertEqual('and', $handlerBase->operator);
$handlerBase = HandlerBase::breakString("{$n1}+{$n2}+{$n3}", TRUE);
$this->assertEqualValue(array($n1, $n2, $n3), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
$handlerBase = HandlerBase::breakString("{$s1},{$n2},{$n3}", TRUE);
$this->assertEqualValue(array((int) $s1, $n2, $n3), $handlerBase);
$this->assertEqual('and', $handlerBase->operator);
$handlerBase = HandlerBase::breakString("{$s1}+{$n2}+{$n3}", TRUE);
$this->assertEqualValue(array((int) $s1, $n2, $n3), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
// Generate three random decimals which can be used below;
$d1 = rand(0, 10) / 10;
$d2 = rand(0, 10) / 10;
$d3 = rand(0, 10) / 10;
// Test "or"s.
$handlerBase = HandlerBase::breakString("{$s1} {$d1}+{$d2}");
$this->assertEqualValue(array($s1, $d1, $d2), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
$handlerBase = HandlerBase::breakString("{$s1}+{$d1}+{$d3}");
$this->assertEqualValue(array($s1, $d1, $d3), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
$handlerBase = HandlerBase::breakString("{$s1} {$d2} {$d3}");
$this->assertEqualValue(array($s1, $d2, $d3), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
$handlerBase = HandlerBase::breakString("{$s1} {$d2}++{$d3}");
$this->assertEqualValue(array($s1, $d2, $d3), $handlerBase);
$this->assertEqual('or', $handlerBase->operator);
// Test "and"s.
$handlerBase = HandlerBase::breakString("{$s1},{$d2},{$d3}");
//.........这里部分代码省略.........
示例4: summaryNameField
/**
* Add the name field, which is the field displayed in summary queries.
* This is often used when the argument is numeric.
*/
protected function summaryNameField()
{
// Add the 'name' field. For example, if this is a uid argument, the
// name field would be 'name' (i.e, the username).
if (isset($this->name_table)) {
// if the alias is different then we're probably added, not ensured,
// so look up the join and add it instead.
if ($this->tableAlias != $this->name_table) {
$j = HandlerBase::getTableJoin($this->name_table, $this->table);
if ($j) {
$join = clone $j;
$join->leftTable = $this->tableAlias;
$this->name_table_alias = $this->query->addTable($this->name_table, $this->relationship, $join);
}
} else {
$this->name_table_alias = $this->query->ensureTable($this->name_table, $this->relationship);
}
} else {
$this->name_table_alias = $this->tableAlias;
}
if (isset($this->name_field)) {
$this->name_alias = $this->query->addField($this->name_table_alias, $this->name_field);
} else {
$this->name_alias = $this->base_alias;
}
}
示例5: testBreakPhrase
/**
* Tests Drupal\views\Plugin\views\HandlerBase::breakPhrase() function.
*/
function testBreakPhrase()
{
$empty_stdclass = new \stdClass();
$empty_stdclass->operator = 'or';
$empty_stdclass->value = array();
$null = NULL;
// check defaults
$this->assertEqual($empty_stdclass, HandlerBase::breakPhrase('', $null));
$item = array('table' => 'node', 'field' => 'title');
$handler = $this->container->get('plugin.manager.views.argument')->getHandler($item);
$this->assertEqual($handler, HandlerBase::breakPhrase('', $handler), 'The breakPhrase() method works correctly.');
// Generate three random numbers which can be used below;
$n1 = rand(0, 100);
$n2 = rand(0, 100);
$n3 = rand(0, 100);
// test ors
$this->assertEqualValue(array($n1, $n2, $n3), HandlerBase::breakPhrase("{$n1} {$n2}+{$n3}", $handler));
$this->assertEqual('or', $handler->operator);
$this->assertEqualValue(array($n1, $n2, $n3), HandlerBase::breakPhrase("{$n1}+{$n2}+{$n3}", $handler));
$this->assertEqual('or', $handler->operator);
$this->assertEqualValue(array($n1, $n2, $n3), HandlerBase::breakPhrase("{$n1} {$n2} {$n3}", $handler));
$this->assertEqual('or', $handler->operator);
$this->assertEqualValue(array($n1, $n2, $n3), HandlerBase::breakPhrase("{$n1} {$n2}++{$n3}", $handler));
$this->assertEqual('or', $handler->operator);
// test ands.
$this->assertEqualValue(array($n1, $n2, $n3), HandlerBase::breakPhrase("{$n1},{$n2},{$n3}", $handler));
$this->assertEqual('and', $handler->operator);
$this->assertEqualValue(array($n1, $n2, $n3), HandlerBase::breakPhrase("{$n1},,{$n2},{$n3}", $handler));
$this->assertEqual('and', $handler->operator);
}
示例6: buildOptionsForm
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
if ($form_state->get('type') != 'empty') {
$form['empty'] = array('#type' => 'checkbox', '#title' => $this->t('Display even if view has no result'), '#default_value' => isset($this->options['empty']) ? $this->options['empty'] : 0);
}
}
示例7: buildOptionsForm
/**
* Basic options for all sort criteria
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
if ($this->canExpose()) {
$this->showExposeButton($form, $form_state);
}
$form['op_val_start'] = array('#value' => '<div class="clearfix">');
$this->showSortForm($form, $form_state);
$form['op_val_end'] = array('#value' => '</div>');
if ($this->canExpose()) {
$this->showExposeForm($form, $form_state);
}
}
示例8: adminLabel
public function adminLabel($short = FALSE)
{
return $this->getField(parent::adminLabel($short));
}
示例9: buildOptionsForm
/**
* Provide the basic form which calls through to subforms.
* If overridden, it is best to call through to the parent,
* or to at least make sure all of the functions in this form
* are called.
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
if ($this->canExpose()) {
$this->showExposeButton($form, $form_state);
}
if ($this->canBuildGroup()) {
$this->showBuildGroupButton($form, $form_state);
}
$form['clear_markup_start'] = array('#markup' => '<div class="clearfix">');
if ($this->isAGroup()) {
if ($this->canBuildGroup()) {
$form['clear_markup_start'] = array('#markup' => '<div class="clearfix">');
// Render the build group form.
$this->showBuildGroupForm($form, $form_state);
$form['clear_markup_end'] = array('#markup' => '</div>');
}
} else {
// Add the subform from operatorForm().
$this->showOperatorForm($form, $form_state);
// Add the subform from valueForm().
$this->showValueForm($form, $form_state);
$form['clear_markup_end'] = array('#markup' => '</div>');
if ($this->canExpose()) {
// Add the subform from buildExposeForm().
$this->showExposeForm($form, $form_state);
}
}
}
示例10: buildOptionsForm
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state)
{
parent::buildOptionsForm($form, $form_state);
unset($form['admin_label']['#fieldset']);
$form['admin_label']['#weight'] = -1;
$form['required'] = array('#type' => 'checkbox', '#title' => $this->t('Require this relationship'), '#description' => $this->t('Enable to hide items that do not contain this relationship'), '#default_value' => !empty($this->options['required']));
}