You are here

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

Try to get the content from a Request object.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

Return value

\Drupal\opigno_group_manager\OpignoGroupContent|false The content if possible. FALSE otherwise.

Overrides ContentTypeInterface::getContentFromRequest

File

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

Class

ContentTypeModule
Class ContentTypeModule.

Namespace

Drupal\opigno_module\Plugin\OpignoGroupManagerContentType

Code

public function getContentFromRequest(Request $request) {

  // If the route is not an Opigno module route, leave the function.
  $route_name = $request->attributes
    ->get('_route');
  if (!in_array($route_name, [
    'entity.opigno_module.canonical',
    'opigno_module.take_module',
    'opigno_module.group.answer_form',
    'opigno_module.my_results',
    'opigno_module.group.my_results',
    'opigno_module.module_result',
    'opigno_module.module_result_form',
  ]) || $request->attributes
    ->has('opigno_module') == FALSE) {
    return FALSE;
  }

  /* @var $opigno_module OpignoModule */
  $opigno_module = $request->attributes
    ->get('opigno_module');
  if (empty($opigno_module) || $opigno_module
    ->getEntityTypeId() != 'opigno_module') {
    return FALSE;
  }
  return new OpignoGroupContent($this
    ->getPluginId(), $this
    ->getEntityType(), $opigno_module
    ->id(), $opigno_module
    ->getName(), ($image_url = $this
    ->getModuleImageUrl($opigno_module)) ? $image_url : $this
    ->getDefaultModuleImageUrl(), $image_url ? $this
    ->getModuleImageAlt($opigno_module) : t('Default image'));
}