I have created a page(Page Manager) in drupal 8 with a path say /dashboard/{nodeid}. Inside that I have created a Panel and inside panel I have added a Custom Block ( which I created programmatically by extending BlockBase). Now my problem is I want to use the {nodeid} inside my buildForm function.

Please suggest me.

My code is as follows.


class ABCBlock extends BlockBase

    public function build() {  

        return \Drupal::formBuilder()->getForm('Drupal\examples\Form\ABCForm');




class ABCForm extends FormBase

    public function getFormId() {
      return 'example_ABCForm';     

    public function buildForm(array $form, FormStateInterface $form_state)    {

      drupal_set_message('Hello World.'); // displaying fine.
      $tmp = arg(0);//or arg(1) which i am assuming as url parameter value. But it FAILS.

      //load node object using $tmp



While a very different question, the answer is the same as mine in https://drupal.stackexchange.com/a/188629/31.

In short, define a context on your block, make sure that the parameter in page manager is defined as type node and the rest should just work.

  • What if I just need to pass a string? Jul 25 '17 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.