-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ea0b854
Showing
7 changed files
with
404 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: 'Configuration Entity View' | ||
description: 'Views handler implementation for configuration entities.' | ||
core: 8.x | ||
type: module | ||
version: VERSION | ||
package: Views |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
/** | ||
* @file | ||
* Contains Config Views implementation. | ||
*/ | ||
|
||
/** | ||
* Helper to get the configuration for views. | ||
*/ | ||
|
||
function config_views_query() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Provide views data for dblog.module. | ||
*/ | ||
|
||
/** | ||
* Implements hook_views_data(). | ||
*/ | ||
function config_views_views_data() { | ||
$data = array(); | ||
|
||
$data['config_views']['table']['group'] = t('Configuration'); | ||
$data['config_views']['table']['wizard_id'] = 'config_entity'; | ||
$data['config_views']['table']['base'] = array( | ||
'query_id' => 'config_entity_query', | ||
'field' => 'id', | ||
'title' => t('Configuration Entity'), | ||
'help' => t('Contains list of configuration entities.'), | ||
); | ||
|
||
$data['config_views']['id'] = array( | ||
'title' => t('Machine name'), | ||
'help' => t('Unique configuration entity ID.'), | ||
'field' => array( | ||
'id' => 'config_entity', | ||
), | ||
'filter' => array( | ||
'id' => 'string', | ||
), | ||
'argument' => array( | ||
'id' => 'string', | ||
), | ||
'sort' => array( | ||
'id' => 'standard', | ||
), | ||
'search' => array( | ||
'id' => 'standard', | ||
), | ||
); | ||
|
||
$data['config_views']['name'] = array( | ||
'title' => t('Name'), | ||
'help' => t('Name'), | ||
'field' => array( | ||
'id' => 'config_entity', | ||
), | ||
'filter' => array( | ||
'id' => 'string', | ||
), | ||
'argument' => array( | ||
'id' => 'string', | ||
), | ||
'sort' => array( | ||
'id' => 'standard', | ||
), | ||
'search' => array( | ||
'id' => 'standard', | ||
), | ||
); | ||
|
||
$data['config_views']['description'] = array( | ||
'title' => t('Description'), | ||
'help' => t('Description'), | ||
'field' => array( | ||
'id' => 'config_entity', | ||
), | ||
'filter' => array( | ||
'id' => 'string', | ||
), | ||
'argument' => array( | ||
'id' => 'string', | ||
), | ||
'sort' => array( | ||
'id' => 'standard', | ||
), | ||
'search' => array( | ||
'id' => 'standard', | ||
), | ||
); | ||
|
||
$data['config_views']['operation'] = array( | ||
'title' => t('Operations'), | ||
'help' => t('Operations'), | ||
'field' => array( | ||
'id' => 'config_entity', | ||
), | ||
); | ||
|
||
|
||
return $data; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Definition of Drupal\config_views\Plugin\views\field\Node. | ||
*/ | ||
|
||
namespace Drupal\config_views\Plugin\views\field; | ||
|
||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\views\ResultRow; | ||
use Drupal\views\ViewExecutable; | ||
use Drupal\views\Plugin\views\display\DisplayPluginBase; | ||
use Drupal\views\Plugin\views\field\FieldPluginBase; | ||
|
||
/** | ||
* Field handler to provide simple renderer that allows linking to a entity. | ||
* Definition terms: | ||
* - link_to_entity default: Should this field have the checkbox "link to node" enabled by default. | ||
* | ||
* @ingroup views_field_handlers | ||
* | ||
* @ViewsField("config_entity") | ||
*/ | ||
class ConfigEntity extends FieldPluginBase { | ||
|
||
/** | ||
* Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::init(). | ||
*/ | ||
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { | ||
parent::init($view, $display, $options); | ||
|
||
// Don't add the additional fields to groupby | ||
if (!empty($this->options['link_to_entity'])) { | ||
$this->additional_fields['nid'] = array('table' => 'node', 'field' => 'nid'); | ||
} | ||
} | ||
|
||
protected function defineOptions() { | ||
$options = parent::defineOptions(); | ||
$options['link_to_entity'] = array('default' => isset($this->definition['link_to_entity default']) ? $this->definition['link_to_entity default'] : FALSE); | ||
return $options; | ||
} | ||
|
||
/** | ||
* Provide link to node option | ||
*/ | ||
public function link_to_entity(&$form, FormStateInterface $form_state) { | ||
$form['link_to_entity'] = array( | ||
'#title' => $this->t('Link this field to the original piece of content'), | ||
'#description' => $this->t("Enable to override this field's links."), | ||
'#type' => 'checkbox', | ||
'#default_value' => !empty($this->options['link_to_entity']), | ||
); | ||
|
||
parent::buildOptionsForm($form, $form_state); | ||
} | ||
|
||
/** | ||
* Prepares link to the entity. | ||
* | ||
* @param string $data | ||
* The XSS safe string for the link text. | ||
* @param \Drupal\views\ResultRow $values | ||
* The values retrieved from a single row of a view's query result. | ||
* | ||
* @return string | ||
* Returns a string for the link text. | ||
*/ | ||
protected function renderLink($data, ResultRow $values) { | ||
return $data; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function render(ResultRow $values) { | ||
$this->field_alias = $this->field; | ||
$value = $this->getValue($values); | ||
return $this->renderLink($this->sanitizeValue($value), $values); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Definition of Drupal\config_views\Plugin\views\field\Node. | ||
*/ | ||
|
||
namespace Drupal\config_views\Plugin\views\field; | ||
|
||
use Drupal\views\Plugin\views\field\FieldPluginBase; | ||
|
||
/** | ||
* | ||
* @ingroup views_field_handlers | ||
* | ||
* @ViewsField("config_entity_id") | ||
*/ | ||
class ConfigEntityId extends FieldPluginBase { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\config_views\Plugin\views\query\ConfigEntityQuery. | ||
*/ | ||
|
||
namespace Drupal\config_views\Plugin\views\query; | ||
|
||
use Drupal\Component\Utility\NestedArray; | ||
use Drupal\Core\Database\Database; | ||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\views\Plugin\views\display\DisplayPluginBase; | ||
use Drupal\Core\Database\DatabaseExceptionWrapper; | ||
use Drupal\views\Plugin\views\join\JoinPluginBase; | ||
use Drupal\views\Plugin\views\HandlerBase; | ||
use Drupal\views\ResultRow; | ||
use Drupal\views\ViewExecutable; | ||
use Drupal\views\Views; | ||
use Drupal\views\Plugin\views\query\QueryPluginBase; | ||
|
||
/** | ||
* Views query plugin for an SQL query. | ||
* | ||
* @ingroup views_query_plugins | ||
* | ||
* @ViewsQuery( | ||
* id = "config_entity_query", | ||
* title = @Translation("Configuration entity query"), | ||
* help = @Translation("Query will be generated and run using the Drupal database API.") | ||
* ) | ||
*/ | ||
class ConfigEntityQuery extends QueryPluginBase { | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
function execute(ViewExecutable $view) { | ||
|
||
$results = array( | ||
array( | ||
'id' => '1', | ||
'name' => 'name1', | ||
'description' => 'ddd1', | ||
'operation' => 'ddd1', | ||
), | ||
array( | ||
'id' => '2', | ||
'name' => 'name2', | ||
'description' => 'ddd2', | ||
'operation' => 'ddd2', | ||
), | ||
array( | ||
'id' => '3', | ||
'name' => 'name', | ||
'description' => 'ddd', | ||
'operation' => 'ddd', | ||
), | ||
array( | ||
'id' => '4', | ||
'name' => 'name', | ||
'description' => 'ddd', | ||
'operation' => 'ddd', | ||
), | ||
); | ||
|
||
foreach ($results as $result) { | ||
$view->result[] = new ResultRow($result); | ||
} | ||
} | ||
|
||
|
||
public function ensureTable($table, $relationship = NULL, JoinPluginBase $join = NULL) { | ||
return; | ||
} | ||
|
||
public function addField($table, $field, $alias = '', $params = array()) { | ||
return $alias; | ||
} | ||
} |
Oops, something went wrong.