class NestedSetStorageFactory in Entity Reference Hierarchy 3.x
Same name and namespace in other branches
- 8.2 src/Storage/NestedSetStorageFactory.php \Drupal\entity_hierarchy\Storage\NestedSetStorageFactory
Defines a factory for creating a nested set storage handler for hierarchies.
Hierarchy
- class \Drupal\entity_hierarchy\Storage\NestedSetStorageFactory
Expanded class hierarchy of NestedSetStorageFactory
10 files declare their use of NestedSetStorageFactory
- ChildEntityWarningBuilder.php in src/
Information/ ChildEntityWarningBuilder.php - ChildOfMicrositeLookup.php in modules/
entity_hierarchy_microsite/ src/ ChildOfMicrositeLookup.php - EntityHierarchy.php in src/
Plugin/ EntityReferenceSelection/ EntityHierarchy.php - EntityHierarchy.php in modules/
entity_hierarchy_workbench_access/ src/ Plugin/ AccessControlHierarchy/ EntityHierarchy.php - EntityHierarchyArgumentPluginBase.php in src/
Plugin/ views/ argument/ EntityHierarchyArgumentPluginBase.php
1 string reference to 'NestedSetStorageFactory'
1 service uses NestedSetStorageFactory
File
- src/
Storage/ NestedSetStorageFactory.php, line 12
Namespace
Drupal\entity_hierarchy\StorageView source
class NestedSetStorageFactory {
/**
* DBAL connection.
*
* @var \Doctrine\DBAL\Connection
*/
protected $connection;
/**
* Static cache.
*
* @var array
*/
protected $cache = [];
/**
* Table prefix.
*
* @var string
*/
protected $tablePrefix = '';
/**
* Logger.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* Constructs a new NestedSetStorageFactory object.
*
* @param \Doctrine\DBAL\Connection $connection
* Dbal Connection.
* @param \Drupal\Core\Database\Connection $drupalConnection
* Drupal connection.
* @param \Psr\Log\LoggerInterface $logger
* Logger.
*/
public function __construct(Connection $connection, DrupalConnection $drupalConnection, LoggerInterface $logger) {
$this->connection = $connection;
$this->tablePrefix = $drupalConnection
->tablePrefix();
$this->logger = $logger;
}
/**
* Gets a new nested set storage handler.
*
* @param string $field_name
* Field name for storage.
* @param string $entity_type_id
* Entity Type ID.
*
* @return \Drupal\entity_hierarchy\Storage\NestedSetStorage
* Nested set for given field.
*/
public function get($field_name, $entity_type_id) {
$table_name = $this
->getTableName($field_name, $entity_type_id);
return $this
->fromTableName($table_name);
}
/**
* Gets a new nested set storage handler for the given table.
*
* @param string $table_name
* Table name.
*
* @return \Drupal\entity_hierarchy\Storage\NestedSetStorage
* Nested set for given field.
*
* @todo Remove this in favour of derivative argument plugins?
*/
public function fromTableName($table_name) {
if (!isset($this->cache[$table_name])) {
$this->cache[$table_name] = new NestedSetStorage($this->connection, $table_name, $this->logger);
}
return $this->cache[$table_name];
}
/**
* Gets table name for a given field name and entity type.
*
* @param string $field_name
* Field name.
* @param string $entity_type_id
* Entity Type ID.
* @param bool $withPrefix
* (optional) TRUE to add prefix. Views data does not need prefix.
*
* @return string
* Table name.
*/
public function getTableName($field_name, $entity_type_id, $withPrefix = TRUE) {
return sprintf('%snested_set_%s_%s', $withPrefix ? $this->tablePrefix : '', $field_name, $entity_type_id);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
NestedSetStorageFactory:: |
protected | property | Static cache. | |
NestedSetStorageFactory:: |
protected | property | DBAL connection. | |
NestedSetStorageFactory:: |
protected | property | Logger. | |
NestedSetStorageFactory:: |
protected | property | Table prefix. | |
NestedSetStorageFactory:: |
public | function | Gets a new nested set storage handler for the given table. | |
NestedSetStorageFactory:: |
public | function | Gets a new nested set storage handler. | |
NestedSetStorageFactory:: |
public | function | Gets table name for a given field name and entity type. | |
NestedSetStorageFactory:: |
public | function | Constructs a new NestedSetStorageFactory object. |