You are here

class CustomIconThemer in Geofield Map 8.2

Style plugin to render a View output as a Leaflet map.

Attributes set below end up in the $this->definition[] array.

Plugin annotation


@MapThemer(
  id = "geofieldmap_custom_icon",
  name = @Translation("Custom Icon Image File (geofield_map) - Image Upload (deprecated)"),
  description = "This Geofield Map Themer allows the definition of a unique
custom Marker Icon, valid for all the Map Markers.",
  context = {"ViewStyle"},
  weight = 0,
  markerIconSelection = {
   "type" = "managed_file",
   "configSyncCompatibility" = FALSE,
  },
  defaultSettings = {
   "values" = {},
   "legend" = {
     "class" = "custom-icon",
    },
  }
)

Hierarchy

Expanded class hierarchy of CustomIconThemer

File

src/Plugin/GeofieldMapThemer/CustomIconThemer.php, line 37

Namespace

Drupal\geofield_map\Plugin\GeofieldMapThemer
View source
class CustomIconThemer extends MapThemerBase {

  /**
   * {@inheritdoc}
   */
  public function buildMapThemerElement(array $defaults, array &$form, FormStateInterface $form_state, GeofieldGoogleMapViewStyle $geofieldMapView) {

    // Get the existing (Default) Element settings.
    $default_element = $this
      ->getDefaultThemerElement($defaults);
    $file_upload_help = $this->markerIcon
      ->getFileUploadHelp();
    $fid = (int) (!empty($default_element['icon_file']['fids'])) ? $default_element['icon_file']['fids'] : NULL;
    $element = [
      '#markup' => Markup::create($this
        ->t('<label>Custom Icon Image File</label>')),
      '#type' => 'container',
      'description' => [
        '#markup' => Markup::create($this
          ->t('The chosen icon file will be used as Marker for all Geofield Map features @file_upload_help', [
          '@file_upload_help' => $this->renderer
            ->renderPlain($file_upload_help),
        ])),
      ],
      'icon_file' => $this->markerIcon
        ->getIconFileManagedElement($fid[0]),
      'image_style' => [
        '#type' => 'select',
        '#title' => $this
          ->t('Image style'),
        '#options' => $this->markerIcon
          ->getImageStyleOptions(),
        '#default_value' => isset($default_element['image_style']) ? $default_element['image_style'] : 'geofield_map_default_icon_style',
        '#states' => [
          'visible' => [
            ':input[name="style_options[map_marker_and_infowindow][theming][geofieldmap_custom_icon][values][icon_file][is_svg]"]' => [
              'checked' => FALSE,
            ],
          ],
        ],
      ],
      'image_style_svg' => [
        '#type' => 'container',
        'warning' => [
          '#markup' => $this
            ->t("Image style cannot apply to SVG Files,<br>SVG natural dimension will be applied."),
        ],
        '#states' => [
          'invisible' => [
            ':input[name="style_options[map_marker_and_infowindow][theming][geofieldmap_custom_icon][values][icon_file][is_svg]"]' => [
              'checked' => FALSE,
            ],
          ],
        ],
      ],
      'label_alias' => [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Label alias'),
        '#default_value' => isset($default_element['label_alias']) ? $default_element['label_alias'] : '',
        '#description' => $this
          ->t('If not empty, this will be used in the legend.'),
        '#size' => 20,
      ],
    ];
    return $element;
  }

  /**
   * {@inheritdoc}
   */
  public function getIcon(array $datum, GeofieldGoogleMapViewStyle $geofieldMapView, EntityInterface $entity, $map_theming_values) {

    // The Custom Icon Themer plugin defines a unique icon value.
    if (!empty($map_theming_values['icon_file']['fids'])) {
      $image_style = isset($map_theming_values['image_style']) ? $map_theming_values['image_style'] : 'none';
      return $this->markerIcon
        ->getFileManagedUrl($map_theming_values['icon_file']['fids'][0], $image_style);
    }
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function getLegend(array $map_theming_values, array $configuration = []) {
    $legend = $this
      ->defaultLegendHeader($configuration);

    // Get the icon image style, as result of the Legend configuration.
    $image_style = isset($configuration['markers_image_style']) ? $configuration['markers_image_style'] : 'none';

    // Get the map_theming_image_style, is so set.
    if (isset($configuration['markers_image_style']) && $configuration['markers_image_style'] == '_map_theming_image_style_') {
      $image_style = isset($map_theming_values['image_style']) ? $map_theming_values['image_style'] : 'none';
    }
    $fid = (int) (!empty($map_theming_values['icon_file']['fids'])) ? $map_theming_values['icon_file']['fids'][0] : NULL;
    $legend['table']['custom-icon'] = [
      'value' => [
        '#type' => 'container',
        'label' => [
          '#markup' => !empty($map_theming_values['label_alias']) ? $map_theming_values['label_alias'] : $this
            ->t('All Markers'),
        ],
        '#attributes' => [
          'class' => [
            'value',
          ],
        ],
      ],
      'marker' => [
        '#type' => 'container',
        'icon_file' => !empty($fid) ? $this->markerIcon
          ->getLegendIconFromFid($fid, $image_style) : $this
          ->getDefaultLegendIcon(),
        '#attributes' => [
          'class' => [
            'marker',
          ],
        ],
      ],
    ];
    $legend['notes'] = [
      '#markup' => isset($configuration['legend_notes']) ? $configuration['legend_notes'] : '',
      '#attributes' => [
        'class' => [
          'notes',
        ],
      ],
    ];
    return $legend;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CustomIconThemer::buildMapThemerElement public function Provides a Map Themer Options Element. Overrides MapThemerInterface::buildMapThemerElement
CustomIconThemer::getIcon public function Retrieve the icon for theming definition. Overrides MapThemerInterface::getIcon
CustomIconThemer::getLegend public function Generate the Legend render array. Overrides MapThemerInterface::getLegend
MapThemerBase::$config protected property The config factory service. 2
MapThemerBase::$entityManager protected property The Entity type manager service.
MapThemerBase::$markerIcon protected property The Icon Managed File Service.
MapThemerBase::$renderer protected property The Renderer service property.
MapThemerBase::$translationManager protected property The translation manager.
MapThemerBase::buildDefaultMapThemerRow protected function Builds the base table row for multivalue MapThemer.
MapThemerBase::buildTableHeader protected function Returns Default Table Header.
MapThemerBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 3
MapThemerBase::defaultLegendFooter protected function Returns the default Legend Footer.
MapThemerBase::defaultLegendHeader protected function Returns the default Legend Header.
MapThemerBase::defaultSettings public function Get the defaultSettings for the Map Themer Plugin. Overrides MapThemerInterface::defaultSettings
MapThemerBase::getDefaultLegendIcon protected function Returns the default Icon output for the Legend.
MapThemerBase::getDefaultThemerElement public function
MapThemerBase::getDescription public function Get the MapThemer description property. Overrides MapThemerInterface::getDescription
MapThemerBase::getLabelAliasHelp public function Generate Label Alias Help Message.
MapThemerBase::getMapThemerEntityBundles protected function Gets the Map Themer Entity Bundles, based on the View Style Entity Type.
MapThemerBase::getName public function Get the MapThemer name property. Overrides MapThemerInterface::getName
MapThemerBase::renderDefaultLegendIcon protected function Define if to return the default Legend Icon.
MapThemerBase::__construct public function Constructs a Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct 3
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.