I'm trying to accomplish a certain task and clueless. Im using Drupal 8 for my new project.I have a slideshow in my home page and I've used 'flexslider' plugin and views for achieving this. This is working as expected.
But in all of my inner pages, I have a header where I'm supposed to display the last image displayed on the slideshow of the front page.
For this, I'm trying to create a dynamic custom block programmatically based on the URL parameter. (I have the last image details with me and did an ajax post to my custom module when the image changes on the slideshow).
For example in Drupal 7 we would do something like this:
In my hello.module I will add
<?php
/**
* @file
* hello module
*
*/
/*
* Implementation of hook_menu
*/
function hello_menu() {
$items = array();
$items['test/%'] = array(
'title' => t('Test'),
'description' => t('Test'),
'page callback' => '_test',
'page arguments' => array(1),
'access callback' => TRUE,
'type' => MENU_CALLBACK
);
return $items;
}
function _test($variable) {
$output = $variable;
return $output;
}
function hello_block_info() {
$block = array();
$block['test']['info'] = t('Test Block');
return $block;
}
function hello_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'test':
$block['subject'] = t('Test block');
$block['content'] = t('Here is the content');
}
return $block;
}
?>Here, we would be able to change the block content based on the switch statement.
How, can this be accomplished in Drupal 8.
I have created a custom module and a block as well, but cant get the url parameter into the 'build()' function.
Is there any other way to achieve the same in Drupal 8?
Thanks.
Comments
Any suggestions?
I am ready to change the approach if its not the right way.
To get the raw url use the
To get the raw url use the following:
$current_path = \Drupal::service('path.current')->getPath(); //returns /node/1234If you need the path aliased url:
$request = \Drupal::request()->getRequestUri();