class ConfigActionsFile in Config Actions 8
Plugin for config source from files.
Plugin annotation
@ConfigActionsSource(
id = "file",
description = @Translation("Use a file."),
weight = "-1",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\config_actions\ConfigActionsSourceBase implements ConfigActionsSourceInterface, ContainerFactoryPluginInterface
- class \Drupal\config_actions\Plugin\ConfigActionsSource\ConfigActionsFile
- class \Drupal\config_actions\ConfigActionsSourceBase implements ConfigActionsSourceInterface, ContainerFactoryPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ConfigActionsFile
1 file declares its use of ConfigActionsFile
- ConfigActionsSourceTest.php in tests/
src/ Kernel/ ConfigActionsSourceTest.php
File
- src/
Plugin/ ConfigActionsSource/ ConfigActionsFile.php, line 21
Namespace
Drupal\config_actions\Plugin\ConfigActionsSourceView source
class ConfigActionsFile extends ConfigActionsSourceBase {
/**
* @var string
* The name of the default sub-directory containing config templates.
*/
const CONFIG_TEMPLATE_DIRECTORY = 'config/templates';
/**
* @var \Drupal\Core\File\FileSystem
*/
protected $fileSystem;
/**
* Constructs a new ConfigActionsSource object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param ConfigActionsServiceInterface $config_action_service
* The ConfigActionsService from the container.
* @param FileSystem $file_system
* The FileSystem from the container.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigActionsServiceInterface $config_action_service, FileSystem $file_system) {
$this->fileSystem = $file_system;
parent::__construct($configuration, $plugin_id, $plugin_definition, $config_action_service);
}
/**
* Create a plugin instance from the container
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* @param array $configuration
* @param string $plugin_id
* @param mixed $plugin_definition
* @return static
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
/** @var ConfigActionsServiceInterface $config_action_service */
$config_action_service = $container
->get('config_actions');
/** @var FileSystem $file_system */
$file_system = $container
->get('file_system');
return new static($configuration, $plugin_id, $plugin_definition, $config_action_service, $file_system);
}
/**
* {@inheritdoc}
*/
public function detect($source) {
$extension = '.' . FileStorage::getFileExtension();
return is_string($source) && substr($source, -strlen($extension)) === $extension;
}
/**
* Return the file name and path from the source specifier
* @param $source
* @param string $base
* Optional base path
* @return array
* 0 - file name
* 1 - file path
*/
protected function filePath($source, $base = '') {
$filepath = $this->fileSystem
->dirname($source);
$filename = $this->fileSystem
->basename($source, '.' . FileStorage::getFileExtension());
// See if Source specifies its own path or not.
if (empty($filepath) || $filepath == '.') {
// Path not specified, so use provided base or current directory.
$base = !empty($base) ? $base : dirname(__FILE__);
$filepath = $base . '/' . self::CONFIG_TEMPLATE_DIRECTORY;
}
elseif (!empty($base)) {
// If path was specified in Source, prepend any provided base path.
$filepath = $base . '/' . $filepath;
}
return [
$filepath,
$filename,
];
}
/**
* {@inheritdoc}
*/
public function doLoad() {
$this
->setMerge(TRUE);
list($filepath, $filename) = $this
->filePath($this->sourceId, $this->sourceBase);
$template_storage = new FileStorage($filepath, StorageInterface::DEFAULT_COLLECTION);
return $template_storage
->read($filename);
}
/**
* {@inheritdoc}
*/
public function doSave($data) {
list($filepath, $filename) = $this
->filePath($this->sourceId, $this->sourceBase);
$template_storage = new FileStorage($filepath, StorageInterface::DEFAULT_COLLECTION);
return $template_storage
->write($filename, $data);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigActionsFile:: |
protected | property | ||
ConfigActionsFile:: |
constant | The name of the default sub-directory containing config templates. | ||
ConfigActionsFile:: |
public static | function |
Create a plugin instance from the container Overrides ConfigActionsSourceBase:: |
|
ConfigActionsFile:: |
public | function |
Determine if $source is valid for the specific plugin. Overrides ConfigActionsSourceBase:: |
|
ConfigActionsFile:: |
public | function |
Load data from the source. Overrides ConfigActionsSourceBase:: |
|
ConfigActionsFile:: |
public | function |
Save data to the source. Overrides ConfigActionsSourceBase:: |
|
ConfigActionsFile:: |
protected | function | Return the file name and path from the source specifier | |
ConfigActionsFile:: |
public | function |
Constructs a new ConfigActionsSource object. Overrides ConfigActionsSourceBase:: |
|
ConfigActionsSourceBase:: |
protected | property | ||
ConfigActionsSourceBase:: |
protected | property | Determine if sourceData has been changed since last load/save. | |
ConfigActionsSourceBase:: |
protected | property | ||
ConfigActionsSourceBase:: |
protected | property | The type of the plugin instance | |
ConfigActionsSourceBase:: |
protected | property | The Base namespace for the source. Plugin specific. | |
ConfigActionsSourceBase:: |
protected | property | The cached config data for this source instance. | |
ConfigActionsSourceBase:: |
protected | property | The ID value of the source. Plugin specific. | |
ConfigActionsSourceBase:: |
public | function |
Get the data cached from the last load/save. Overrides ConfigActionsSourceInterface:: |
|
ConfigActionsSourceBase:: |
public | function |
Return whether the data from this source will be merged Overrides ConfigActionsSourceInterface:: |
|
ConfigActionsSourceBase:: |
public | function |
Return the type of plugin. Overrides ConfigActionsSourceInterface:: |
|
ConfigActionsSourceBase:: |
public | function |
Return TRUE if the data has changed since the last load. Overrides ConfigActionsSourceInterface:: |
|
ConfigActionsSourceBase:: |
public | function |
Load data from the source. Overrides ConfigActionsSourceInterface:: |
|
ConfigActionsSourceBase:: |
public | function |
Save data to the source. Overrides ConfigActionsSourceInterface:: |
|
ConfigActionsSourceBase:: |
public | function |
Set the data cached in this plugin instance.
Causes the plugin to be marked as Changed. Overrides ConfigActionsSourceInterface:: |
|
ConfigActionsSourceBase:: |
public | function |
Set whether data saved in this source should be merged with existing data Overrides ConfigActionsSourceInterface:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |