Skip to content

Instantly share code, notes, and snippets.

@arfaram
Last active November 22, 2019 16:50
Show Gist options
  • Save arfaram/120850f2ff149f2a8092b1cc1fcc93ab to your computer and use it in GitHub Desktop.
Save arfaram/120850f2ff149f2a8092b1cc1fcc93ab to your computer and use it in GitHub Desktop.
eZ Platform Image path generation
//Image Path Example
// var/site/storage/images/0/5/5/7/7550-6-ger-DE/Homepage-banner.jpg
// Returns a relative storage path
// Computes a 4 levels directory structure from $id , more info in ezcontentobject_attribute "ezimage" and "id" columns
// our base path is the last 4 digits, defaulting to 0, reversed
// getStoragePathForField($fieldId, $versionNo, $languageCode) of the curent published content
//use eZ\Publish\Core\FieldType\Image\PathGenerator\LegacyPathGenerator;
$legacyPathGenerator = new LegacyPathGenerator();
$legacyPathGenerator->getStoragePathForField(2,3,'eng-GB'); // 2/0/0/0/2-3-eng-GB
$legacyPathGenerator->getStoragePathForField(12,3,'eng-GB'); // 2/1/0/0/12-3-eng-GB
$legacyPathGenerator->getStoragePathForField(345,3,'eng-GB'); // 5/4/3/0/345-3-eng-GB
$legacyPathGenerator->getStoragePathForField(3456,3,'eng-GB'); // 5/4/3/3456-3-eng-GB
$legacyPathGenerator->getStoragePathForField(34567,3,'eng-GB'); // 7/6/5/4/34567-3-eng-GB
$legacyPathGenerator->getStoragePathForField(3456789,3,'eng-GB'); // 9/8/7/6/3456789-3-eng-GB
$legacyPathGenerator->getStoragePathForField(8888,3,'eng-GB'); // 8/8/8/8/8888-3-eng-GB
$legacyPathGenerator->getStoragePathForField(128888,3,'eng-GB'); // 8/8/8/8/128888-3-eng-GB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment