diff --git a/media_remote.module b/media_remote.module index fcd2872..0ef0d15 100644 --- a/media_remote.module +++ b/media_remote.module @@ -145,6 +145,13 @@ function media_remote_theme($existing, $type, $theme, $path) { 'height' => NULL, ], ], + 'media_remote_google_map' => [ + 'variables' => [ + 'url' => NULL, + 'width' => NULL, + 'height' => NULL, + ], + ], 'media_remote_libsyn' => [ 'variables' => [ 'episode_id' => NULL, diff --git a/src/Plugin/Field/FieldFormatter/MediaRemoteGoogleMapFormatter.php b/src/Plugin/Field/FieldFormatter/MediaRemoteGoogleMapFormatter.php new file mode 100644 index 0000000..01d5750 --- /dev/null +++ b/src/Plugin/Field/FieldFormatter/MediaRemoteGoogleMapFormatter.php @@ -0,0 +1,123 @@ + $url, + ]); + } + return parent::deriveMediaDefaultNameFromUrl($url); + } + + /** + * {@inheritdoc} + */ + public function viewElements(FieldItemListInterface $items, $langcode) { + $elements = []; + foreach ($items as $delta => $item) { + /** @var \Drupal\Core\Field\FieldItemInterface $item */ + if ($item->isEmpty()) { + continue; + } + $elements[$delta] = [ + '#theme' => 'media_remote_google_map', + '#url' => $item->value, + '#width' => $this->getSetting('width') ?? 960, + '#height' => $this->getSetting('height') ?? 600, + ]; + } + return $elements; + } + + /** + * {@inheritdoc} + */ + public static function defaultSettings() { + return [ + 'width' => 960, + 'height' => 600, + ] + parent::defaultSettings(); + } + + /** + * {@inheritdoc} + */ + public function settingsForm(array $form, FormStateInterface $form_state) { + return parent::settingsForm($form, $form_state) + [ + 'width' => [ + '#type' => 'number', + '#title' => $this->t('Width'), + '#default_value' => $this->getSetting('width'), + '#size' => 5, + '#maxlength' => 5, + '#field_suffix' => $this->t('pixels'), + '#min' => 50, + ], + 'height' => [ + '#type' => 'number', + '#title' => $this->t('Height'), + '#default_value' => $this->getSetting('height'), + '#size' => 5, + '#maxlength' => 5, + '#field_suffix' => $this->t('pixels'), + '#min' => 50, + ], + ]; + } + + /** + * {@inheritdoc} + */ + public function settingsSummary() { + $summary = parent::settingsSummary(); + $summary[] = $this->t('Iframe size: %width x %height pixels', [ + '%width' => $this->getSetting('width'), + '%height' => $this->getSetting('height'), + ]); + return $summary; + } + +} diff --git a/templates/media-remote-google-map.html.twig b/templates/media-remote-google-map.html.twig new file mode 100644 index 0000000..687295a --- /dev/null +++ b/templates/media-remote-google-map.html.twig @@ -0,0 +1,12 @@ +{# +/** + * @file + * Template implementation for the media_remote_google_map theme hook. + * + * Available variables: + * - url: (string) The full URL to this document. + * - width: (int) The width of the iframe, in pixels. + * - height: (int) The height of the iframe, in pixels. + */ +#} +