3 namespace Drupal\file_mdm\Plugin;
5 use Drupal\Component\Plugin\PluginInspectionInterface;
6 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
7 use Drupal\Core\Plugin\PluginFormInterface;
10 * Provides an interface defining a FileMetadata plugin.
12 interface FileMetadataPluginInterface extends ContainerFactoryPluginInterface, PluginInspectionInterface, PluginFormInterface {
15 * Gets default configuration for this plugin.
18 * An associative array with the default configuration.
20 public static function defaultConfiguration();
23 * Sets the URI of the file.
30 * @throws \Drupal\file_mdm\FileMetadataException
31 * If no URI is specified.
33 public function setUri($uri);
36 * Gets the URI of the file.
39 * The URI of the file.
41 public function getUri();
44 * Sets the local filesystem path to the file.
46 * This is used to allow accessing local copies of files stored remotely, to
47 * minimise remote calls and allow functions that cannot access remote stream
48 * wrappers to operate locally.
50 * @param string $temp_path
55 public function setLocalTempPath($temp_path);
58 * Gets the local filesystem path to the file.
60 * This is used to allow accessing local copies of files stored remotely, to
61 * minimise remote calls and allow functions that cannot access remote stream
62 * wrappers to operate locally.
65 * The local filesystem path to the file.
67 public function getLocalTempPath();
70 * Sets the hash used to reference the URI by the metadata manager.
77 * @throws \Drupal\file_mdm\FileMetadataException
78 * If no hash is specified.
80 public function setHash($hash);
83 * Returns a list of metadata keys supported by the plugin.
85 * @param mixed $options
86 * (optional) Allows specifying additional options to control the list of
87 * metadata keys returned.
90 * A simple array of metadata keys supported.
92 public function getSupportedKeys($options = NULL);
95 * Checks if file metadata has been already loaded.
98 * TRUE if metadata is loaded, FALSE otherwise.
100 public function isMetadataLoaded();
103 * Loads file metadata from an in-memory object/array.
105 * @param mixed $metadata
106 * The file metadata associated to the file at URI.
109 * TRUE if metadata was loaded successfully, FALSE otherwise.
111 public function loadMetadata($metadata);
114 * Loads file metadata from the file at URI/local path.
117 * TRUE if metadata was loaded successfully, FALSE otherwise.
119 * @throws \Drupal\file_mdm\FileMetadataException
120 * In case there were significant errors reading from file.
122 public function loadMetadataFromFile();
125 * Loads file metadata from a cache entry.
128 * TRUE if metadata was loaded successfully, FALSE otherwise.
130 * @throws \Drupal\file_mdm\FileMetadataException
131 * In case of significant errors.
133 public function loadMetadataFromCache();
136 * Gets a metadata element.
138 * @param mixed|null $key
139 * A key to determine the metadata element to be returned. If NULL, the
140 * entire metadata will be returned.
143 * The value of the element specified by $key. If $key is NULL, the entire
146 public function getMetadata($key = NULL);
149 * Sets a metadata element.
152 * A key to determine the metadata element to be changed.
153 * @param mixed $value
154 * The value to change the metadata element to.
157 * TRUE if metadata was changed successfully, FALSE otherwise.
159 public function setMetadata($key, $value);
162 * Removes a metadata element.
165 * A key to determine the metadata element to be removed.
168 * TRUE if metadata was removed successfully, FALSE otherwise.
170 public function removeMetadata($key);
173 * Determines if plugin is capable of writing metadata to files.
176 * TRUE if plugin can save data to files, FALSE otherwise.
178 public function isSaveToFileSupported();
181 * Saves metadata to file at URI.
184 * TRUE if metadata was saved successfully, FALSE otherwise.
186 public function saveMetadataToFile();
189 * Caches metadata for file at URI.
191 * Uses the 'file_mdm' cache bin.
194 * (optional) An array of cache tags to save to cache.
197 * TRUE if metadata was saved successfully, FALSE otherwise.
199 public function saveMetadataToCache(array $tags = []);
202 * Removes cached metadata for file at URI.
204 * Uses the 'file_mdm' cache bin.
207 * TRUE if metadata was removed, FALSE otherwise.
209 public function deleteCachedMetadata();