📌  相关文章
📜  如果 drupal 8 字段为空,则获取 - 无论代码示例

📅  最后修改于: 2022-03-11 14:56:08.383000             🧑  作者: Mango

代码示例1
if (!$entity->get('category')->isEmpty()) {
  /** @var EntityInterface $category */
  $category = $entity->get('category')->entity;
  $row['category']['data'] = [
    '#type' => 'link',
    '#title' => $category->get('name')->value,
    '#url' => $category->toUrl(),
  ];
}
else {
  $row['category'] = NULL;
}