Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaycs85 committed Oct 11, 2014
0 parents commit ea0b854
Show file tree
Hide file tree
Showing 7 changed files with 404 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config_views.info.yml
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
13 changes: 13 additions & 0 deletions config_views.module
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() {

}
95 changes: 95 additions & 0 deletions config_views.views.inc
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;

}

83 changes: 83 additions & 0 deletions src/Plugin/views/field/ConfigEntity.php
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);
}

}
20 changes: 20 additions & 0 deletions src/Plugin/views/field/ConfigEntityId.php
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 {

}
79 changes: 79 additions & 0 deletions src/Plugin/views/query/ConfigEntityQuery.php
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;
}
}
Loading

0 comments on commit ea0b854

Please sign in to comment.