class DraggableViews in DraggableViews 2.0.x
Same name in this branch
- 2.0.x src/DraggableViews.php \Drupal\draggableviews\DraggableViews
- 2.0.x src/Plugin/migrate/destination/DraggableViews.php \Drupal\draggableviews\Plugin\migrate\destination\DraggableViews
Same name and namespace in other branches
- 8 src/DraggableViews.php \Drupal\draggableviews\DraggableViews
Class DraggableViews.
Hierarchy
- class \Drupal\draggableviews\DraggableViews
Expanded class hierarchy of DraggableViews
2 files declare their use of DraggableViews
- draggableviews.module in ./
draggableviews.module - Contains draggableviews.module.
- DraggableViewsField.php in src/
Plugin/ views/ field/ DraggableViewsField.php
1 string reference to 'DraggableViews'
File
- src/
DraggableViews.php, line 12
Namespace
Drupal\draggableviewsView source
class DraggableViews {
/**
* The view.
*
* @var \Drupal\views\ViewExecutable
*/
public $view;
/**
* Constructs DraggableViewsRows object.
*
* @param \Drupal\views\ViewExecutable $view
* Views object.
*/
public function __construct(ViewExecutable $view) {
$this->view = $view;
}
/**
* Get index by id.
*/
public function getIndex($id) {
foreach ($this->view->result as $item) {
if ($item->_entity instanceof Media) {
// Media index name.
$name = 'mid';
}
else {
// Node index name. The default one.
$name = 'nid';
}
if ($item->{$name} == $id) {
return $item->index;
}
}
return FALSE;
}
/**
* Get depth by index.
*/
public function getDepth($index) {
if (!isset($this->view->result[$index])) {
return FALSE;
}
$row = $this->view->result[$index];
// If parent is available, set parent's depth +1.
return !empty($row->draggableviews_structure_parent) ? $this
->getDepth($this
->getIndex($row->draggableviews_structure_parent)) + 1 : 0;
}
/**
* Get parent by index.
*/
public function getParent($index) {
return isset($this->view->result[$index]->draggableviews_structure_parent) ? $this->view->result[$index]->draggableviews_structure_parent : 0;
}
/**
* Get ancestor by index.
*/
public function getAncestor($index) {
$row = $this->view->result[$index];
return !empty($row->draggableviews_structure_parent) ? $this
->getAncestor($this
->getIndex($row->draggableviews_structure_parent)) : $index;
}
/**
* Return value by it's name and index.
*/
public function getValue($name, $index) {
return $this->view->result[$index]->{$name};
}
/**
* Get HTML id for draggableviews table.
*/
public function getHtmlId() {
return Html::getId('draggableviews-table-' . $this->view
->id() . '-' . $this->view->current_display);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DraggableViews:: |
public | property | The view. | |
DraggableViews:: |
public | function | Get ancestor by index. | |
DraggableViews:: |
public | function | Get depth by index. | |
DraggableViews:: |
public | function | Get HTML id for draggableviews table. | |
DraggableViews:: |
public | function | Get index by id. | |
DraggableViews:: |
public | function | Get parent by index. | |
DraggableViews:: |
public | function | Return value by it's name and index. | |
DraggableViews:: |
public | function | Constructs DraggableViewsRows object. |