You are here

protected function SettingsForm::determineMapGaps in Sophron 8

Returns an array of gaps of current map vs Drupal's core mapping.

Return value

array An array of simple arrays, each having a file extension, its Drupal MIME type guess, and a gap information.

1 call to SettingsForm::determineMapGaps()
SettingsForm::buildForm in src/Form/SettingsForm.php
Form constructor.

File

src/Form/SettingsForm.php, line 330

Class

SettingsForm
Main Sophron settings admin form.

Namespace

Drupal\sophron\Form

Code

protected function determineMapGaps() {
  $core_extended_guesser = new CoreExtensionMimeTypeGuesserExtended();
  $extensions = $core_extended_guesser
    ->listExtensions();
  sort($extensions);
  $rows = [];
  foreach ($extensions as $extension_string) {
    $drupal_mime_type = $core_extended_guesser
      ->guess('a.' . $extension_string);
    $extension = $this->mimeMapManager
      ->getExtension($extension_string);
    if ($extension) {
      try {
        $mimemap_mime_type = $extension
          ->getDefaultType();
      } catch (\Exception $e) {
        $mimemap_mime_type = '';
      }
    }
    $gap = '';
    if ($mimemap_mime_type === '') {
      $gap = $this
        ->t('No MIME type mapped to this file extension.');
    }
    elseif (mb_strtolower($drupal_mime_type) != mb_strtolower($mimemap_mime_type)) {
      $gap = $this
        ->t("File extension mapped to '@type' instead.", [
        '@type' => $mimemap_mime_type,
      ]);
    }
    if ($gap !== '') {
      $rows[] = [
        $extension_string,
        $drupal_mime_type,
        $gap,
      ];
    }
  }
  return $rows;
}