Custom Element-Dev: How to output element id in control of type Info

Hi everybody,

I try to do the following in set_controls() of my custom class (that extends \Bricks\Element):

<?php

 public function set_controls() {
  
    //this is not working, cause $this->element['id'] is null at that point
    $element_id = $this->element['id'];
    
    
    $this->controls['tg_navInfo'] = [
      'tab' => 'content',
      'content' => 'My Id is: '.$element_id,
      'type' => 'info',
    ];      
  }
?>

I cannot do that, because $this->element is null at that point.

I tried using a filter to change it later on, like this:

<?php

 add_filter( 'bricks/element/settings', function( $settings, $element ) {
            if ( $element->name === 'my_test_class' ) {
                $element->controls['tg_navInfo']['content'] = 'Successfully edited by filter. Element id is '. $element['id']; 
            }
        
            return $settings;
        }, 10, 2 );
?>

But for it returns $settings and doesn’t apply the changes made to the element. So right now, I don’t know how to approach this in the best way. Can anybody help? Thank you!

What about $this->id? :slight_smile:

Hey Daniele, thanks for your answer! I thought the same at first. But if I’m not wrong, $this->id and $this->element[‘id’] are not the same, at least at this point of execution.
In a specific example if I run it with $this->id I get #brxe-aktazd (respectively just aktazd, without prefix) as element id and 059ed1 as $this->id.

I feel lost with this. It seems like a pretty simple task and still I haven’t found a solution.
Maybe some context helps. My goal is the following: I create an Element ‘My_Element’ that CAN be connected to a Navigation-Element ‘My_Element_Nav’. To sync the Elements I need to enter ids from ‘My_Element’ in the Navigation-Element.
The ids will be constructed inside of ‘My_Element’ like:
$element_id + ‘button_prev’
$element_id + ‘button_next’
and so on …

In ‘My_Element’ I want to output that information , so that a user can just copy the identifier and paste it in the corresponding field of the Nav-Component. I haven’t event thought this could be a problem, but well here I am …