You are here

public function ContentTypeModule::getAllContents in Opigno module 8

Same name and namespace in other branches
  1. 3.x src/Plugin/OpignoGroupManagerContentType/ContentTypeModule.php \Drupal\opigno_module\Plugin\OpignoGroupManagerContentType\ContentTypeModule::getAllContents()

Get all the entities in an array of LearningPathContent.

Return value

\Drupal\opigno_group_manager\OpignoGroupContent[]|false The contents or FALSE in case of error.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException

Overrides ContentTypeInterface::getAllContents

File

src/Plugin/OpignoGroupManagerContentType/ContentTypeModule.php, line 160

Class

ContentTypeModule
Class ContentTypeModule.

Namespace

Drupal\opigno_module\Plugin\OpignoGroupManagerContentType

Code

public function getAllContents() {
  try {

    /** @var \Drupal\opigno_module\Entity\OpignoModule[] $modules */
    $modules = \Drupal::entityTypeManager()
      ->getStorage('opigno_module')
      ->loadByProperties([]);
  } catch (InvalidPluginDefinitionException $e) {

    // TODO: Log the error.
    return FALSE;
  }
  $request = \Drupal::request();
  $contents = [];
  foreach ($modules as $module) {
    $contents[] = new OpignoGroupContent($this
      ->getPluginId(), $this
      ->getEntityType(), $module
      ->id(), $module
      ->getName(), ($image_url = $this
      ->getModuleImageUrl($module)) ? $image_url : $this
      ->getDefaultModuleImageUrl(), $image_url ? $this
      ->getModuleImageAlt($module) : t('Default image'));
  }
  return $contents;
}