Skip to main content
added 420 characters in body
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

The function buildRow returns a render array. You can put simple strings directly in the array, because later it will be put in another html structure like a table. An example from core, where it is used both ways (CommentTypeListBuilder.php):

public function buildRow(EntityInterface $entity) {
    $row['type'] = $entity->label();
    $row['description']['data'] = ['#markup' => $entity->getDescription()];
    return $row + parent::buildRow($entity);
  }

So using the '#markup' element is optional. You can use it to be on the safe side, when you don't know how your render array is processed.

For complex elements you need a render element. The method view() would generates this:

$row['email'] = $entity->email->view();

But this does not work. The problem seems to be in the custom entity. According to the error message there is a call to an undefined method render, which should be defined in MyEntity. Your entity does not know how to handle the email field.

If you don't want to theme the field, you can use the value as markup:

$row['email']['#markup'] = $entity->email->value;

Or you can put the field as an object:

$row['email'] = $entity->email;

Or you can build your own render array, for example as a link:

$row['title'] = array(
      '#type' => 'link',
      '#title' => $entity->label(),
      '#url' => $uri,
    );

The function buildRow returns a render array. You can put simple strings directly in the array, because later it will be put in another html structure like a table. An example from core, where it is used both ways (CommentTypeListBuilder.php):

public function buildRow(EntityInterface $entity) {
    $row['type'] = $entity->label();
    $row['description']['data'] = ['#markup' => $entity->getDescription()];
    return $row + parent::buildRow($entity);
  }

So using the '#markup' element is optional. You can use it to be on the safe side, when you don't know how your render array is processed.

For complex elements you need a render element. The method view() would generates this:

$row['email'] = $entity->email->view();

But this does not work. The problem seems to be in the custom entity. According to the error message there is a call to an undefined method render, which should be defined in MyEntity. Your entity does not know how to handle the email field.

The function buildRow returns a render array. You can put simple strings directly in the array, because later it will be put in another html structure like a table. An example from core, where it is used both ways (CommentTypeListBuilder.php):

public function buildRow(EntityInterface $entity) {
    $row['type'] = $entity->label();
    $row['description']['data'] = ['#markup' => $entity->getDescription()];
    return $row + parent::buildRow($entity);
  }

So using the '#markup' element is optional. You can use it to be on the safe side, when you don't know how your render array is processed.

For complex elements you need a render element. The method view() would generates this:

$row['email'] = $entity->email->view();

But this does not work. The problem seems to be in the custom entity. According to the error message there is a call to an undefined method render, which should be defined in MyEntity. Your entity does not know how to handle the email field.

If you don't want to theme the field, you can use the value as markup:

$row['email']['#markup'] = $entity->email->value;

Or you can put the field as an object:

$row['email'] = $entity->email;

Or you can build your own render array, for example as a link:

$row['title'] = array(
      '#type' => 'link',
      '#title' => $entity->label(),
      '#url' => $uri,
    );
added 684 characters in body
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

The function buildRow returns a render array.

This You can put simple strings directly in the array, because later it will be put in another html structure like a table. An example from core, where it is no render elementused both ways (CommentTypeListBuilder.php):

$row['id']public function buildRow(EntityInterface $entity) {
    $row['type'] = $entity->id>label();

This is the most basic form of a render element:

$row['id'] = array(
  $row['description']['data'] '#markup'= ['#markup' => $entity->id>getDescription(),];
    return $row + parent::buildRow($entity);
  }

ThisSo using the '#markup' element is OKoptional. You can use it to be on the safe side, becausewhen you don't know how your render array is processed.

For complex elements you need a render element. The method view() would generates a render arraythis:

$row['email'] = $entity->email->view();

But this does not work. The problem seems to be in the custom entity. According to the error message there is a call to an undefined method render, which should be defined in MyEntity. Your entity does not know how to handle the email field.

The function returns a render array.

This is no render element:

$row['id'] = $entity->id();

This is the most basic form of a render element:

$row['id'] = array(
   '#markup' => $entity->id(),
);

This is OK, because view() generates a render array:

$row['email'] = $entity->email->view();

The function buildRow returns a render array. You can put simple strings directly in the array, because later it will be put in another html structure like a table. An example from core, where it is used both ways (CommentTypeListBuilder.php):

public function buildRow(EntityInterface $entity) {
    $row['type'] = $entity->label();
    $row['description']['data'] = ['#markup' => $entity->getDescription()];
    return $row + parent::buildRow($entity);
  }

So using the '#markup' element is optional. You can use it to be on the safe side, when you don't know how your render array is processed.

For complex elements you need a render element. The method view() would generates this:

$row['email'] = $entity->email->view();

But this does not work. The problem seems to be in the custom entity. According to the error message there is a call to an undefined method render, which should be defined in MyEntity. Your entity does not know how to handle the email field.

Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

The function returns a render array.

This is no render element:

$row['id'] = $entity->id();

This is the most basic form of a render element:

$row['id'] = array(
   '#markup' => $entity->id(),
);

This is OK, because view() generates a render array:

$row['email'] = $entity->email->view();