I built a custom entity. My problem is that the types (except markup) are not rendered properly. I want -as in the module views - to see the result of a radio as status like YES or no:

/**
 * Extending the EntityAPIController for the pricedefault entity.
 */
class PricedefaultEntityController extends EntityAPIController {
  
  public function buildContent($entity, $view_mode = 'full', $langcode = NULL, $content = array()) {

    $build = parent::buildContent($entity, $view_mode, $langcode, $content);
    
    // Our additions to the $build render array.
    $build['kaufpreis'] = array(
      '#type' => 'markup',
      '#markup' => check_plain($entity->kaufpreis),
      '#prefix' => '<div class="pricedefault_kaufpreis">',
      '#suffix' => '</div>',
    );
    $build['auf_anfrage'] = array(
      '#type' => 'radio',
    //  '#markup' => check_plain($entity->auf_anfrage),
      '#prefix' => '<p>Per Demand: ',
      '#suffix' => '</p>',
    );
    $build['vb'] = array(
      '#type' => 'radio',
    //  '#markup' => check_plain($entity->vb),
      '#prefix' => '<p>VB: ',
      '#suffix' => '</p>',
    );
    
    return $build;
  
  }
  
}

Comments

jaypan’s picture

$form['radios'] = array
(
  '#title' => t('OK?'),
  '#type' => 'radios',
  '#options' => t('yes' => t('Yes'), 'no' => t('No')),
  '#default_value' => 'yes',
);

Contact me to contract me for D7 -> D10/11 migrations.

maen’s picture

Sorry Jaypan,

$build['auf_anfrage'] = array(
      '#type' => 'markup',
    //  '#title' => t('On demand'),
      '#markup' => T('On demand:').check_plain($entity->auf_anfrage),
    //   '#options' => array(0 => t('No'), 1 => t('Yes')),
    //  '#default_value' => check_plain($entity->auf_anfrage), 
    //  '#prefix' => '<p>Per Demand: ',
    //  '#suffix' => '</p>',  
    );

Leads to "On demand: 0/1" tqt shows me the result is there.

$build['auf_anfrage'] = array(
      '#type' => 'radios',
      '#title' => t('On demand'),
    //'#markup' => T('On demand:').check_plain($entity->auf_anfrage),
       '#options' => array(0 => t('No'), 1 => t('Yes')),
      '#default_value' => check_plain($entity->auf_anfrage), 
      //'#prefix' => '<p>Per Demand: ',
     // '#suffix' => '</p>',  
    );

Leads to <label>On demand</label> No radio buttons are shown. No 'YES'/ 'No' assignments are visible.

jaypan’s picture

$build['auf_anfrage'] = array(
      '#type' => 'radios',
      '#title' => t('On demand'),
       '#options' => array(0 => t('No'), 1 => t('Yes')),
    );

This code will create radios. If you are not seeing them, change your theme, and try again, as it is likely something in your theme causing the problems.

Contact me to contract me for D7 -> D10/11 migrations.

maen’s picture

and that's the question I believe:

How do I theme a custom entity to render my results as it should?

And: the entity shall not be fieldable. I want to take to call them directly from the table.

jaypan’s picture

This last post doesn't seem to relate to my previous post at all. You are talking about themeing a custom entity, but your code until now has been in relation to Form API elements.

Contact me to contract me for D7 -> D10/11 migrations.

maen’s picture

you' re right: I have to apologize for my question which wasn't clear. But in the beginning I thought that it has sth to do that I didn't took the right form.
But that's as it cleared out for me by your answers, the problem doesn't lie in the question, how tho give the infos to the entity api, now it seems it's the question how to interprete the results coming from the entity, or shorter:
not to put in, instead get the data from the system.