I have a custom entity I've created following this basic SitePoint tutorial. My custom entity has just two properties, a name and description. My entity is not fieldable (maybe it needs to be?.

I want to make the description support text formats so it's not just interpreted as plain text. Ideally the user could choose text formats like they could for something like a text field added thru the field UI, but since my entity is not fieldable and has no UI for adding fields, I'm not sure where to go with this?

1 Answer 1


You'll need another property on your entity to hold the format.

In your entity form builder, use a text_format element, and use a validate to move the desired values into place:

$form['description_placeholder'] = array(
  '#type' => 'text_format',
  '#title' => t('Description'),
  '#format' => empty($entity->description_format) ? 'full_html' : $entity->description_format,
  '#default_value' => empty($entity->description) ? '' : $entity->description,

$form['#validate'][] = 'MYMODULE_entity_validate';


function MYMODULE_entity_validate($form, &$form_state) {
  $form_state['values']['description'] = $form_state['values']['description_placeholder']['value'];
  $form_state['values']['description_format'] = $form_state['values']['description_placeholder']['format'];

When you render, use:

 $formatted = check_markup($entity->description, $entity->description_format);
  • Thank's Clive. Right now I'm just doing the rendering with entity_view, how can I get it to work with that?
    – Brian
    Jul 14, 2014 at 13:18
  • Wherever you're currently preparing description for rendering, you just need to use the above instead. I couldn't tell you where that would be, there are half a dozen or more different ways to get that job done
    – Clive
    Jul 14, 2014 at 14:08
  • Ah, so in my custom entities controller, I manually build the render array in buildContent. In there, I can call check_markup. Thanks again!
    – Brian
    Jul 16, 2014 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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