I admit, using
hook_ds_pre_render_alter() to alter Display Suite layouts can be
a little bit tricky to work with. A much easier way to alter them is to register
your own alter hook.
Registering the Drupal Alter Hook
The idea for this solution is to register an alter hook with
so other modules can alter the render array by entity.
This is going to loop through all the items in each region that belong to the
layout. The item is then passed to an alter hook. The alter hook will depend on
the layout’s entity. For example, a layout that belongs to a
node would be
hook_ds_pre_render_node_alter(), and you would use
to alter that items render array.
With each item the hook will be called with the
(which is the render array),
$layout_render_item argument is important, as this is the render array you
should alter to manipulate the layout output. You can change the hook however to
pass in any arguments you do or don’t need.
Using the Drupal Alter Hook
Here is an example of how you would use the hook. This example will check for the title of a blog post and change it.
Obviously this example may not be a very idealistic use case, but it’s simple enough for you to get the idea of what it does.