vendor/contao/core-bundle/src/File/ModelMetadataTrait.php line 50

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Contao.
  5.  *
  6.  * (c) Leo Feyer
  7.  *
  8.  * @license LGPL-3.0-or-later
  9.  */
  10. namespace Contao\CoreBundle\File;
  11. use Contao\FilesModel;
  12. use Contao\System;
  13. /**
  14.  * @property string $overwriteMeta
  15.  *
  16.  * @method array row()
  17.  */
  18. trait ModelMetadataTrait
  19. {
  20.     /**
  21.      * Get the default metadata or null if not applicable.
  22.      */
  23.     public function getOverwriteMetadata(): ?Metadata
  24.     {
  25.         // Ignore if "overwriteMeta" is not set
  26.         if (!$this->overwriteMeta) {
  27.             return null;
  28.         }
  29.         $data $this->row();
  30.         // Normalize keys
  31.         if (isset($data['imageTitle'])) {
  32.             $data[Metadata::VALUE_TITLE] = $data['imageTitle'];
  33.         }
  34.         if (isset($data['imageUrl'])) {
  35.             $data[Metadata::VALUE_URL] = $data['imageUrl'];
  36.         }
  37.         unset($data['imageTitle'], $data['imageUrl']);
  38.         // Make sure we resolve insert tags pointing to files
  39.         if (isset($data[Metadata::VALUE_URL])) {
  40.             $data[Metadata::VALUE_URL] = System::getContainer()->get('contao.insert_tag.parser')->replaceInline($data[Metadata::VALUE_URL] ?? '');
  41.         }
  42.         // Strip superfluous fields by intersecting with tl_files.meta.eval.metaFields
  43.         return new Metadata(array_intersect_key($dataarray_flip(FilesModel::getMetaFields())));
  44.     }
  45. }