3 namespace Drupal\file_mdm;
6 * Provides an interface for file metadata objects.
8 interface FileMetadataInterface {
11 * Metadata not loaded.
16 * Metadata loaded by code.
18 const LOADED_BY_CODE = 1;
21 * Metadata loaded from cache.
23 const LOADED_FROM_CACHE = 2;
26 * Metadata loaded from file.
28 const LOADED_FROM_FILE = 3;
31 * Gets the URI of the file.
34 * The URI of the file, or a local path.
36 public function getUri();
39 * Gets the local filesystem URI to the temporary file.
42 * The URI, or a local path, of the temporary file.
44 public function getLocalTempPath();
47 * Sets the local filesystem URI to the temporary file.
49 * @param string $temp_uri
50 * A URI to a temporary file.
54 public function setLocalTempPath($temp_uri);
57 * Copies the file at URI to a local temporary file.
59 * @param string $temp_uri
60 * (optional) a URI to a temporary file. If NULL, a temp URI will be
61 * defined by the operation. Defaults to NULL.
64 * TRUE if the file was copied successfully, FALSE
67 public function copyUriToTemp($temp_uri = NULL);
70 * Copies the local temporary file to the destination URI.
73 * TRUE if the file was copied successfully, FALSE
76 public function copyTempToUri();
79 * Gets a FileMetadata plugin instance.
81 * @param string $metadata_id
82 * The id of the plugin whose instance is to be returned. If it is does
83 * not exist, an instance is created.
85 * @return \Drupal\file_mdm\Plugin\FileMetadataPluginInterface|null
86 * The FileMetadata plugin instance. NULL if no plugin is found.
88 public function getFileMetadataPlugin($metadata_id);
91 * Returns a list of supported metadata keys.
93 * @param string $metadata_id
94 * The id of the FileMetadata plugin.
95 * @param mixed $options
96 * (optional) Allows specifying additional options to control the list of
97 * metadata keys returned.
100 * A simple array of metadata keys supported.
102 public function getSupportedKeys($metadata_id, $options = NULL);
105 * Gets a metadata element.
107 * @param string $metadata_id
108 * The id of the FileMetadata plugin.
109 * @param mixed|null $key
110 * A key to determine the metadata element to be returned. If NULL, the
111 * entire metadata will be returned.
114 * The value of the element specified by $key. If $key is NULL, the entire
117 public function getMetadata($metadata_id, $key = NULL);
120 * Removes a metadata element.
122 * @param string $metadata_id
123 * The id of the FileMetadata plugin.
125 * A key to determine the metadata element to be removed.
128 * TRUE if metadata was removed successfully, FALSE otherwise.
130 public function removeMetadata($metadata_id, $key);
133 * Sets a metadata element.
135 * @param string $metadata_id
136 * The id of the FileMetadata plugin.
138 * A key to determine the metadata element to be changed.
139 * @param mixed $value
140 * The value to change the metadata element to.
143 * TRUE if metadata was changed successfully, FALSE otherwise.
145 public function setMetadata($metadata_id, $key, $value);
148 * Checks if file metadata has been already loaded.
150 * @param string $metadata_id
151 * The id of the FileMetadata plugin.
154 * TRUE if metadata is loaded, FALSE otherwise.
156 public function isMetadataLoaded($metadata_id);
159 * Loads file metadata.
161 * @param string $metadata_id
162 * The id of the FileMetadata plugin.
163 * @param mixed $metadata
164 * The file metadata associated to the file at URI.
167 * TRUE if metadata was loaded successfully, FALSE otherwise.
169 public function loadMetadata($metadata_id, $metadata);
172 * Loads file metadata from a cache entry.
174 * @param string $metadata_id
175 * The id of the FileMetadata plugin.
178 * TRUE if metadata was loaded successfully, FALSE otherwise.
180 public function loadMetadataFromCache($metadata_id);
183 * Caches metadata for file at URI.
185 * Uses the 'file_mdm' cache bin.
187 * @param string $metadata_id
188 * The id of the FileMetadata plugin.
190 * (optional) An array of cache tags to save to cache.
193 * TRUE if metadata was saved successfully, FALSE otherwise.
195 public function saveMetadataToCache($metadata_id, array $tags = []);
198 * Saves metadata to file at URI.
200 * @param string $metadata_id
201 * The id of the FileMetadata plugin.
204 * TRUE if metadata was saved successfully, FALSE otherwise.
206 public function saveMetadataToFile($metadata_id);