1. Go to this page and download the library: Download tfd/statamic-aida library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// config/statamic/aida.php
return [
// Custom configuration necessary due to custom alt field handle
'alt_field_mapping' => [
'en' => 'my_custom_alt'
]
];
// config/statamic/aida.php
return [
/**
* No configuration necessary; the addon automatically matches all availables site handles
* to a field `alt_<handle>`, e. g. `alt_en` or `alt_fr`.
*/
'alt_field_mapping' => []
];
// config/statamic/aida.php
return [
/**
* Custom configuration is necessary, because the alt field handles differ from the ones the addon assumes
*/
'alt_field_mapping' => [
'en' => 'alt_english',
'fr' => 'alt_french',
'de' => 'alt_german',
]
];
// config/statamic/aida.php
return [
/**
* Custom configuration defines, for which languages the alt text is being generated.
*/
'alt_field_mapping' => [
'en' => 'alt_en',
'de' => 'alt_de',
]
];
// app/Generator/MyAltTextGenerator.php
namespace App\Generator;
use \Statamic\Assets\Asset;
use TFD\AIDA\Generator\Generator;
class MyAltTextGenerator implements Generator
{
/**
* @param Asset $asset
* @param string $language
* @return string
*/
public function generate($asset, $locale = 'en')
{
/**
* Use some other service to get the alt text from the asset.
* Depending on the service, you might have to transform the asset object
* and use its url or base64 encoded string.
*/
$altText = SomeApi::get($asset, $locale);
/**
* You might want to sanitize the altText with `htmlspecialchars($altText, ENT_QUOTES, 'UTF-8')` to prevent invalid HTML code.
* Alternatively you can use the `sanitize` modifier in your view files.
*/
return $altText;
}
}