You are here

public function RecentVisistorsMapBlock::build in IP Geolocation Views & Maps 8

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

src/Plugin/Block/RecentVisistorsMapBlock.php, line 22

Class

RecentVisistorsMapBlock
IPGV&M: Set my location .

Namespace

Drupal\ip_geoloc\Plugin\Block

Code

public function build() {

  // Calling the set location form in block
  // TODO find a way to add subject.
  $block['subject'] = $this
    ->t('Recent visitors');
  $config = $this
    ->getConfiguration();
  $how_many = $config['ip_geoloc_recent_visitors_map_number_of_visitors'] ? $config['ip_geoloc_recent_visitors_map_number_of_visitors'] : 20;
  $block = [];
  if ($how_many > 0) {
    $map_style = $config['ip_geoloc_recent_visitors_map_div_style'] ? $config['ip_geoloc_recent_visitors_map_div_style'] : IP_GEOLOC_MAP_DIV_DEFAULT_STYLE;
    $locations = ip_geoloc_get_recent_visitor_locations($how_many);
    $map_options = $config['ip_geoloc_recent_visitors_map_options'] ? $config['ip_geoloc_recent_visitors_map_options'] : IP_GEOLOC_RECENT_VISITORS_MAP_OPTIONS;

    // TODO check if it is correct.
    $block = [
      '#theme' => 'ip_geoloc_visitor_map',
      '#locations' => $locations,
      '#div_id' => 'ip-geoloc-block-recent-visitors-map',
      '#map_options' => $map_options,
      '#map_style' => $map_style,
    ];
  }
  return $block;
}