class Font in File metadata manager 8
Same name and namespace in other branches
- 8.2 file_mdm_font/src/Plugin/FileMetadata/Font.php \Drupal\file_mdm_font\Plugin\FileMetadata\Font
FileMetadata plugin for TTF/OTF/WOFF font information.
Uses the 'PHP Font Lib' library (PhenX/php-font-lib).
Plugin annotation
@FileMetadata(
id = "font",
title = @Translation("Font"),
help = @Translation("File metadata plugin for TTF/OTF/WOFF font information, using the PHP Font Lib."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\file_mdm\Plugin\FileMetadata\FileMetadataPluginBase implements FileMetadataPluginInterface
- class \Drupal\file_mdm_font\Plugin\FileMetadata\Font
- class \Drupal\file_mdm\Plugin\FileMetadata\FileMetadataPluginBase implements FileMetadataPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Font
File
- file_mdm_font/
src/ Plugin/ FileMetadata/ Font.php, line 21
Namespace
Drupal\file_mdm_font\Plugin\FileMetadataView source
class Font extends FileMetadataPluginBase {
/**
* {@inheritdoc}
*/
public function getSupportedKeys($options = NULL) {
return array_merge([
'FontType',
'FontWeight',
], array_values(name::$nameIdCodes));
}
/**
* {@inheritdoc}
*/
protected function doGetMetadataFromFile() {
$font = LibFont::load($this
->getLocalTempPath());
// @todo ::parse raises 'Undefined offset' notices in phenx/php-font-lib
// 0.5, suppress errors while upstream is fixed.
@$font
->parse();
$keys = $this
->getSupportedKeys();
$metadata = [];
foreach ($keys as $key) {
$l_key = strtolower($key);
switch ($l_key) {
case 'fonttype':
$metadata[$l_key] = $font
->getFontType();
break;
case 'fontweight':
$metadata[$l_key] = $font
->getFontWeight();
break;
default:
$code = array_search($l_key, array_map('strtolower', name::$nameIdCodes), TRUE);
if ($value = $font
->getNameTableString($code)) {
$metadata[$l_key] = $value;
}
break;
}
}
return $metadata;
}
/**
* Validates a file metadata key.
*
* @return bool
* TRUE if the key is valid.
*
* @throws \Drupal\file_mdm\FileMetadataException
* In case the key is invalid.
*/
protected function validateKey($key, $method) {
if (!is_string($key)) {
throw new FileMetadataException("Invalid metadata key specified", $this
->getPluginId(), $method);
}
if (!in_array(strtolower($key), array_map('strtolower', $this
->getSupportedKeys()), TRUE)) {
throw new FileMetadataException("Invalid metadata key '{$key}' specified", $this
->getPluginId(), $method);
}
return TRUE;
}
/**
* {@inheritdoc}
*/
protected function doGetMetadata($key = NULL) {
if ($key === NULL) {
return $this->metadata;
}
else {
$this
->validateKey($key, __FUNCTION__);
$l_key = strtolower($key);
if (in_array($l_key, array_map('strtolower', $this
->getSupportedKeys()), TRUE)) {
return isset($this->metadata[$l_key]) ? $this->metadata[$l_key] : NULL;
}
return NULL;
}
}
/**
* {@inheritdoc}
*/
protected function doSetMetadata($key, $value) {
throw new FileMetadataException('Changing font metadata is not supported', $this
->getPluginId());
}
/**
* {@inheritdoc}
*/
protected function doRemoveMetadata($key) {
throw new FileMetadataException('Deleting font metadata is not supported', $this
->getPluginId());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 | |
FileMetadataPluginBase:: |
protected | property | The cache service. | |
FileMetadataPluginBase:: |
protected | property | The config factory. | |
FileMetadataPluginBase:: |
protected | property | The hash used to reference the URI. | |
FileMetadataPluginBase:: |
protected | property | Track if file metadata on cache needs update. | |
FileMetadataPluginBase:: |
protected | property | Track if metadata has been changed from version on file. | |
FileMetadataPluginBase:: |
protected | property | The metadata loading status. | |
FileMetadataPluginBase:: |
protected | property | The local filesystem path to the file. | |
FileMetadataPluginBase:: |
protected | property | The metadata of the file. | |
FileMetadataPluginBase:: |
protected | property | The URI of the file. | |
FileMetadataPluginBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
FileMetadataPluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
FileMetadataPluginBase:: |
public static | function |
Gets default configuration for this plugin. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Removes cached metadata for file at URI. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
protected | function | Saves metadata to file at URI. | 1 |
FileMetadataPluginBase:: |
protected | function | Gets the configuration object for this plugin. | |
FileMetadataPluginBase:: |
public | function |
Gets the local filesystem path to the file. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Gets a metadata element. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
protected | function | Gets metadata to save to cache. | |
FileMetadataPluginBase:: |
public | function |
Gets the URI of the file. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Checks if file metadata has been already loaded. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Determines if plugin is capable of writing metadata to files. Overrides FileMetadataPluginInterface:: |
1 |
FileMetadataPluginBase:: |
protected | function | Checks if file metadata should be cached. | |
FileMetadataPluginBase:: |
public | function |
Loads file metadata from an in-memory object/array. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Loads file metadata from a cache entry. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Loads file metadata from the file at URI/local path. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Removes a metadata element. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Caches metadata for file at URI. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Saves metadata to file at URI. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Sets the hash used to reference the URI by the metadata manager. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Sets the local filesystem path to the file. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Sets a metadata element. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Sets the URI of the file. Overrides FileMetadataPluginInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
FileMetadataPluginBase:: |
public | function |
Constructs a FileMetadataPluginBase plugin. Overrides PluginBase:: |
1 |
Font:: |
protected | function |
Gets a metadata element. Overrides FileMetadataPluginBase:: |
|
Font:: |
protected | function |
Gets file metadata from the file at URI/local path. Overrides FileMetadataPluginBase:: |
|
Font:: |
protected | function |
Removes a metadata element. Overrides FileMetadataPluginBase:: |
|
Font:: |
protected | function |
Sets a metadata element. Overrides FileMetadataPluginBase:: |
|
Font:: |
public | function |
Returns a list of metadata keys supported by the plugin. Overrides FileMetadataPluginInterface:: |
|
Font:: |
protected | function | Validates a file metadata key. | |
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. |