$types =
[];
// Only use block types the user has access to.
foreach ($this->blockContentTypeStorage->
loadMultiple() as $type) { $access =
$this->
entityTypeManager()->
getAccessControlHandler('block_content'
)->
createAccess($type->
id(), NULL,
[], TRUE
);
if ($access->
isAllowed()) { $types[$type->
id()] =
$type;
} } uasort($types,
[$this->blockContentTypeStorage->
getEntityType()->
getClass(), 'sort'
]);
if ($types &&
count($types) == 1
) { $type =
reset($types);
return $this->
addForm($type,
$request);
} if (count($types) === 0
) { return [ '#markup' =>
$this->
t('You have not created any block types yet. Go to the <a href=":url">block type creation page</a> to add a new block type.',
[ ':url' => Url::
fromRoute('block_content.type_add'
)->
toString(),
]),
];
} return ['#theme' => 'block_content_add_list', '#content' =>
$types];
}