0

I want to load the paragraph id in theme preprocess.

function theme_preprocess_layout(&$variables) {
  $ID = $variables['content']['#paragraph'] ???; "contents - protected 'id' => array(1) = 68"
  $variables['attributes'] = new Drupal\Core\Template\Attribute($variables['attributes']);
  $variables['attributes']->addClass($ID);}

It gives me the available method "load($id)" but I don't know how to implement this method.

1
  • 1
    All entities support the id() method. So, try $variables['content']['#paragraph']->id();. See api.drupal.org/api/drupal/….
    – Beau
    Commented Mar 18, 2020 at 5:50

1 Answer 1

0

Thanks to Beau for the help. The method is simply

$ID = $variables['content']['#paragraph']->id();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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