public function EntityTypeThemerUrl::buildMapThemerElement in Geofield Map 8.2
Provides a Map Themer Options Element.
Parameters
array $defaults: The default values/settings.
array $form: The form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
\Drupal\geofield_map\Plugin\views\style\GeofieldGoogleMapViewStyle $geofieldMapView: The Geofield Map View display object.
Return value
array The Map Themer Options Element
Overrides MapThemerInterface::buildMapThemerElement
1 method overrides EntityTypeThemerUrl::buildMapThemerElement()
- EntityTypeThemer::buildMapThemerElement in src/
Plugin/ GeofieldMapThemer/ EntityTypeThemer.php - Provides a Map Themer Options Element.
File
- src/
Plugin/ GeofieldMapThemer/ EntityTypeThemerUrl.php, line 105
Class
- EntityTypeThemerUrl
- Style plugin to render a View output as a Leaflet map.
Namespace
Drupal\geofield_map\Plugin\GeofieldMapThemerCode
public function buildMapThemerElement(array $defaults, array &$form, FormStateInterface $form_state, GeofieldGoogleMapViewStyle $geofieldMapView) {
// Get the existing (Default) Element settings.
$default_element = $this
->getDefaultThemerElement($defaults);
// Get the MapThemer Entity type and bundles.
$entity_type = $geofieldMapView
->getViewEntityType();
$entity_bundles = $this->entityTypeBundleInfo
->getBundleInfo($entity_type);
// Filter the View Bundles based on the View Filtered Bundles,
// but only if the MapThemer is working on the View base table entity type.
$view_bundles = $this
->getMapThemerEntityBundles($geofieldMapView, $entity_type, $entity_bundles);
// Reorder the entity bundles based on existing (Default) Element settings.
if (!empty($default_element)) {
$weighted_bundles = [];
foreach ($view_bundles as $bundle) {
$weighted_bundles[$bundle] = [
'weight' => isset($default_element[$bundle]) ? $default_element[$bundle]['weight'] : 0,
];
}
uasort($weighted_bundles, 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
$view_bundles = array_keys($weighted_bundles);
}
$label_alias_upload_help = $this
->getLabelAliasHelp();
$file_select_help = $this->markerIcon
->getFileSelectHelp();
// Define the Table Header variables.
$table_settings = [
'header' => [
'label' => $this
->t('@entity type Type/Bundle', [
'@entity type' => $entity_type,
]),
'label_alias' => Markup::create($this
->t('Label Alias @description', [
'@description' => $this->renderer
->renderPlain($label_alias_upload_help),
])),
'marker_icon' => Markup::create($this
->t('Marker Icon @file_select_help', [
'@file_select_help' => $this->renderer
->renderPlain($file_select_help),
])),
'image_style' => '',
],
'tabledrag_group' => 'bundles-order-weight',
'caption' => [
'title' => [
'#type' => 'html_tag',
'#tag' => 'label',
'#value' => $this
->t('Icon Urls, per Entity Types'),
],
],
];
// Build the Table Header.
$element = $this
->buildTableHeader($table_settings);
foreach ($view_bundles as $k => $bundle) {
$icon_file_uri = !empty($default_element[$bundle]['icon_file']) ? $default_element[$bundle]['icon_file'] : NULL;
$label_value = $entity_bundles[$bundle]['label'];
// Define the table row parameters.
$row = [
'id' => "[geofieldmap_entity_type_url][values][{$bundle}]",
'label' => [
'value' => $label_value,
'markup' => $label_value,
],
'weight' => [
'value' => isset($default_element[$bundle]['weight']) ? $default_element[$bundle]['weight'] : $k,
'class' => $table_settings['tabledrag_group'],
],
'label_alias' => [
'value' => isset($default_element[$bundle]['label_alias']) ? $default_element[$bundle]['label_alias'] : '',
],
'icon_file_uri' => $icon_file_uri,
'legend_exclude' => [
'value' => isset($default_element[$bundle]['legend_exclude']) ? $default_element[$bundle]['legend_exclude'] : (count($view_bundles) > 10 ? TRUE : FALSE),
],
'attributes' => [
'class' => [
'draggable',
],
],
];
// Builds the table row for the MapThemer.
$element[$bundle] = $this
->buildDefaultMapThemerRow($row);
}
return $element;
}