You are here

public function ExifContent::checkTitle in Exif 8.2

Same name and namespace in other branches
  1. 8 src/ExifContent.php \Drupal\exif\ExifContent::checkTitle()

Allow to fill the title with exif data.

Used in hook exif_entity_create.

Parameters

string $entityType: The entity type name to be modified.

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity to look for metadata fields.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

src/ExifContent.php, line 51

Class

ExifContent
Class ExifContent make link between drupal content and file content.

Namespace

Drupal\exif

Code

public function checkTitle($entityType, FieldableEntityInterface $entity) {
  $bundles_to_check = $this
    ->getBundleForExifData();
  if (in_array($entity
    ->bundle(), $bundles_to_check)) {
    $exif = ExifFactory::getExifInterface();
    $ar_exif_fields = $this
      ->filterFieldsOnSettings($entityType, $entity);
    $ar_exif_fields = $exif
      ->getMetadataFields($ar_exif_fields);
    foreach ($ar_exif_fields as $drupal_field => $metadata_field_descriptor) {
      $field_name = $drupal_field;
      if ($field_name == 'title') {
        $field = $entity
          ->get($field_name);
        if ($field
          ->isEmpty()) {
          $field
            ->appendItem("EXIF_FILLED");
        }
        break;
      }
    }
  }
}