You are here

public function OpignoGroupContent::toManagerArray in Opigno group manager 8

Same name and namespace in other branches
  1. 3.x src/OpignoGroupContent.php \Drupal\opigno_group_manager\OpignoGroupContent::toManagerArray()

Returns OpignoGroupContent params.

Parameters

\Drupal\opigno_group_manager\Entity\OpignoGroupManagedContent|null $content: Content.

Return value

array OpignoGroupContent params.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

src/OpignoGroupContent.php, line 53

Class

OpignoGroupContent
Class OpignoGroupContent.

Namespace

Drupal\opigno_group_manager

Code

public function toManagerArray(OpignoGroupManagedContent $content = NULL) {
  if ($content === NULL) {
    $cid = '';
    $is_mandatory = FALSE;
    $success_score_min = 0;
    $parents_links = [];
    $is_in_skills_system = FALSE;
  }
  else {
    $cid = $content
      ->id();
    $is_mandatory = $content
      ->isMandatory();
    $success_score_min = $content
      ->getSuccessScoreMin();
    $parents_links = $content
      ->getParentsLinks();
    $is_in_skills_system = $content
      ->isInSkillSystem();
  }
  $entity = \Drupal::entityTypeManager()
    ->getStorage($this
    ->getEntityType())
    ->load($this
    ->getEntityId());
  $this_array = [
    'cid' => $cid,
    'entityId' => $this
      ->getEntityId(),
    'contentType' => $this
      ->getGroupContentTypeId(),
    'title' => $this
      ->getTitle(),
    'imageUrl' => $this
      ->getImageUrl(),
    'imageAlt' => $this
      ->getImageAlt(),
    'isMandatory' => $is_mandatory,
    'successScoreMin' => $success_score_min,
    'editable' => $entity
      ->access('update'),
    'in_skills_system' => $is_in_skills_system,
  ];
  $parents = [];
  foreach ($parents_links as $link) {
    if (get_class($link) != 'Drupal\\opigno_group_manager\\Entity\\OpignoGroupManagedLink') {
      continue;
    }
    $parents[] = [
      'cid' => $link
        ->getParentContentId(),
      'minScore' => $link
        ->getRequiredScore(),
      'activities' => $link
        ->getRequiredActivities(),
    ];
  }
  $this_array['parents'] = $parents;
  return $this_array;
}