Issue with getVolatileData

I have a special view for search which only consists of

$entity = $vars['entity'];
echo elgg_view_entity($entity, array("full_view" => false));

But that does not respect getVolatileData, so in the views/default/object/file.php I am trying

if (!$full_view) {
         $entity->description = $vars['entity']->getVolatileData('search_matched_description');

But that has no effect. Where to set this value so elgg_view_entity($entity); is using this ?

  • It does work, if you just had a description to the object in the brief view in the first place :-)

  • $entity->description = $vars['entity']->getVolatileData('search_matched_description');

     

    I don't think this is the line you want, you don't want to set the description of the entity to be the volatile data.  You should just use the volatile data in the view.

  • @Matt, you are probably right. This is what I do now in the dedicated view for search

    if(!$entity->description) {       

                            $entity->description = $entity->getVolatileData('search_matched_description');

    }

    Is there a better way, like in the view for the object ?

    It works and I also understand why, but I still do not know how it is intended to work.

  • Why not do something like:

    $description = $entity->getVolatileData('search_matched_description');

    if (!$description) {

        $description = $entity->description;

    }

    That way you use the volatile data first if there is any, and fall back to the entity description if there isn't any volatile data.

  • Agreed, much better !

    But I still do not understand why I have to declare that specifically in the search view. Why is VolatileData not fed in  $vars['entity']; by default in description and comments ?

  • I'm not sure what you mean, the idea behind volatile data is that it's transient and may not the be the same from pageload to pageload.  Why don't you use a specific search view instead of trying to shoehorn volatile data into the default entity view?

  • That was the issue ! This plugin has a dedicated search view that was only grabbing $vars[entity] and than view it. Since it didn't include volatile data I was sent into the bushes on how to do this.

    To be able to get volatile data you need to fetch it first. I learned that from the search plugin and now included that into the plugin specfic search view.

    Since it is now fixed, we do not need to elaborate on this much. In hindsight it is more of a suggestion to feed it by default, but there are probably more important things to tackle in core than this one.

  • I'm unsure what you mean by 'feed it by default' though