You are here

public function ContentTypeModule::getAvailableContents 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::getAvailableContents()

Get all the published entities in an array of LearningPathContent.

Return value

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

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException

Overrides ContentTypeInterface::getAvailableContents

File

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

Class

ContentTypeModule
Class ContentTypeModule.

Namespace

Drupal\opigno_module\Plugin\OpignoGroupManagerContentType

Code

public function getAvailableContents() {
  try {

    /** @var \Drupal\opigno_module\Entity\OpignoModule[] $modules */
    $modules = \Drupal::entityTypeManager()
      ->getStorage('opigno_module')
      ->loadByProperties([
      'status' => 1,
    ]);
  } 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;
}