While using the entity2text module to render various commerce-related entites to text: Would it be feasible to generally use a php-based "html to text"-library like this one (derived from roundcube code) to convert the raw html output of an entity view mode to text instead of using the custom renderarray_to_text method?

The text output would be dependent on the html output which has it's downsides, but also many benefits and should automatically handle problems with more complex field outputs like addressfield.

I could provide a patch if this is a direction the maintainer is willing to take, I'm using the library quite successfully, but I'm sure there will be a few things to work out.

Comments

tedbow’s picture

What about having changing this module to having a hook_entity2text_converter_info that would let other modules provide converters.

Then there could be a settings page that let the admin select which converter they want to use.

This module could also implement hook_entity2text_converter_info to provide the current converter(entity2text_renderarray_to_text)and then maybe 1 other one. Or just let other modules declare their own.

the hook would be something like this

function hook_entity2text_converter_info() {
$converters['machine_name'] = array(
  'title' => t('the name'),
  'description' => t('more details'),
  'file' => file to include like hook_menu
  'callback' => 'callback_function',
);
return $converters;
}
archnode’s picture

Thanks for the quick feedback - sounds like a plan! I'll look into it when I get the chance and will provide a patch. As the new converter with an external library - Is that something you would want as part of this module, as a submodule for example, or do you prefer I'll create my own module/sandbox using the new hook?

anybody’s picture

This idea is really really useful and makes a lot of sense. I believe that there will never be really good results if we continue to transform the rendered entity output manually... I believe it would be much better to put the rendered entity HTML through a converter to get things done a lot cleaner.