You are here

public function GeofieldMapWidget::settingsSummary in Geofield Map 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/GeofieldMapWidget.php \Drupal\geofield_map\Plugin\Field\FieldWidget\GeofieldMapWidget::settingsSummary()

Returns a short summary for the current widget settings.

If an empty result is returned, a UI can still be provided to display a settings form in case the widget has configurable settings.

Return value

array A short summary of the widget settings.

Overrides GeofieldLatLonWidget::settingsSummary

File

src/Plugin/Field/FieldWidget/GeofieldMapWidget.php, line 524

Class

GeofieldMapWidget
Plugin implementation of the 'geofield_map' widget.

Namespace

Drupal\geofield_map\Plugin\Field\FieldWidget

Code

public function settingsSummary() {
  $gmap_api_key = $this
    ->getGmapApiKey();
  $map_library = [
    '#markup' => $this
      ->t('Map Library: @state', [
      '@state' => 'gmap' == $this
        ->getSetting('map_library') ? 'Google Maps' : 'Leaflet Js',
    ]),
  ];
  $map_type = [
    '#markup' => $this
      ->t('Map Type: @state', [
      '@state' => 'leaflet' == $this
        ->getSetting('map_library') ? $this
        ->getSetting('map_type_leaflet') : $this
        ->getSetting('map_type_google'),
    ]),
  ];

  // Define the Google Maps API Key value message string.
  if (!empty($gmap_api_key)) {
    $state = $this->link
      ->generate($gmap_api_key, Url::fromRoute('geofield_map.settings', [], [
      'query' => [
        'destination' => Url::fromRoute('<current>')
          ->toString(),
      ],
    ]));
  }
  else {
    $state = t("<span class='geofield-map-warning'>Gmap Api Key missing<br>Geocode functionalities not available.</span> @settings_page_link", [
      '@settings_page_link' => $this->link
        ->generate(t('Set it in the Geofield Map Configuration Page'), Url::fromRoute('geofield_map.settings', [], [
        'query' => [
          'destination' => Url::fromRoute('<current>')
            ->toString(),
        ],
      ])),
    ]);
  }
  $map_gmap_api_key = [
    '#markup' => $this
      ->t('Google Maps API Key: @state', [
      '@state' => $state,
    ]),
  ];
  $map_google_places = [
    '#markup' => $this
      ->t('Google Places Autocomplete Service: @state', [
      '@state' => $this
        ->getSetting('map_google_places')['places_control'] ? $this
        ->t('enabled') : $this
        ->t('disabled'),
    ]),
  ];
  $map_type_selector = [
    '#markup' => $this
      ->t('Map Type Selector: @state', [
      '@state' => $this
        ->getSetting('map_type_selector') ? $this
        ->t('enabled') : $this
        ->t('disabled'),
    ]),
  ];
  $map_dimensions = [
    '#markup' => $this
      ->t('Map Dimensions -'),
  ];
  $map_dimensions['#markup'] .= ' ' . $this
    ->t('Width: @state;', [
    '@state' => $this
      ->getSetting('map_dimensions')['width'],
  ]);
  $map_dimensions['#markup'] .= ' ' . $this
    ->t('Height: @state;', [
    '@state' => $this
      ->getSetting('map_dimensions')['height'],
  ]);
  $map_zoom_levels = [
    '#markup' => $this
      ->t('Zoom Levels -'),
  ];
  $map_zoom_levels['#markup'] .= ' ' . $this
    ->t('Start: @state;', [
    '@state' => $this
      ->getSetting('zoom')['start'],
  ]);
  $map_zoom_levels['#markup'] .= ' ' . $this
    ->t('Focus: @state;', [
    '@state' => $this
      ->getSetting('zoom')['focus'],
  ]);
  $map_zoom_levels['#markup'] .= ' ' . $this
    ->t('Min: @state;', [
    '@state' => $this
      ->getSetting('zoom')['min'],
  ]);
  $map_zoom_levels['#markup'] .= ' ' . $this
    ->t('Max: @state;', [
    '@state' => $this
      ->getSetting('zoom')['max'],
  ]);
  $html5 = [
    '#markup' => $this
      ->t('HTML5 Geolocation button: @state', [
      '@state' => $this
        ->getSetting('html5_geolocation') ? $this
        ->t('enabled') : $this
        ->t('disabled'),
    ]),
  ];
  $map_center = [
    '#markup' => $this
      ->t('Click to find marker: @state', [
      '@state' => $this
        ->getSetting('click_to_find_marker') ? $this
        ->t('enabled') : $this
        ->t('disabled'),
    ]),
  ];
  $marker_center = [
    '#markup' => $this
      ->t('Click to place marker: @state', [
      '@state' => $this
        ->getSetting('click_to_place_marker') ? $this
        ->t('enabled') : $this
        ->t('disabled'),
    ]),
  ];
  $geoaddress_field_field = [
    '#markup' => $this
      ->t('Geoaddress Field: @state', [
      '@state' => '0' != $this
        ->getSetting('geoaddress_field')['field'] ? $this
        ->getSetting('geoaddress_field')['field'] : $this
        ->t('- any -'),
    ]),
  ];
  $geoaddress_field_hidden = [
    '#markup' => '0' != $this
      ->getSetting('geoaddress_field')['field'] ? $this
      ->t('Geoaddress Field Hidden: @state', [
      '@state' => $this
        ->getSetting('geoaddress_field')['hidden'],
    ]) : '',
  ];
  $geoaddress_field_disabled = [
    '#markup' => '0' != $this
      ->getSetting('geoaddress_field')['field'] ? $this
      ->t('Geoaddress Field Disabled: @state', [
      '@state' => $this
        ->getSetting('geoaddress_field')['disabled'],
    ]) : '',
  ];
  $summary = [
    'map_gmap_api_key' => $map_gmap_api_key,
    'map_google_places' => $map_google_places,
    'map_library' => $map_library,
    'map_type' => $map_type,
    'map_type_selector' => $map_type_selector,
    'map_dimensions' => $map_dimensions,
    'map_zoom_levels' => $map_zoom_levels,
    'html5' => $html5,
    'map_center' => $map_center,
    'marker_center' => $marker_center,
    'field' => $geoaddress_field_field,
    'hidden' => $geoaddress_field_hidden,
    'disabled' => $geoaddress_field_disabled,
  ];

  // Attach Geofield Map Library.
  $summary['library'] = [
    '#attached' => [
      'library' => [
        'geofield_map/geofield_map_general',
      ],
    ],
  ];
  return $summary;
}