You are here

private function OnlyOne::addAditionalInfoToContentTypes in Allow a content type only once (Only One) 8

Add additional information to the content types.

Parameters

array $content_types: The content types.

2 calls to OnlyOne::addAditionalInfoToContentTypes()
OnlyOne::getAvailableContentTypesSummarized in src/OnlyOne.php
Return the available content types with their number of nodes.
OnlyOne::getNotAvailableContentTypesSummarized in src/OnlyOne.php
Return the not available content types with their number of nodes.

File

src/OnlyOne.php, line 360

Class

OnlyOne
Class OnlyOne.

Namespace

Drupal\onlyone

Code

private function addAditionalInfoToContentTypes(array &$content_types) {

  // Getting the content types label list.
  $content_types_list_label = $this
    ->getContentTypesList();

  // Getting configured content types.
  $configured_content_types = $this->configFactory
    ->get('onlyone.settings')
    ->get('onlyone_node_types');

  // Iterating over all the content types.
  foreach ($content_types as $conten_type => $content_type_info) {

    // Getting the total of languages.
    $cant = count($content_type_info);

    // Iterating over each language.
    for ($i = 0; $i < $cant; $i++) {
      $content_types[$conten_type][$i]->configured = in_array($conten_type, $configured_content_types) ? TRUE : FALSE;

      // Adding the content type name.
      $content_types[$conten_type][$i]->name = $content_types_list_label[$conten_type];

      // The format for multilingual is diferent from non multilingual sites.
      if ($this->languageManager
        ->isMultilingual()) {

        // Getting the language label.
        $language = $this
          ->getLanguageLabel($content_type_info[$i]->language);

        // Adding text with total nodes.
        $total_nodes = $content_type_info[$i]->total ? $this
          ->formatPlural($content_type_info[$i]->total, '@language: @total Node', '@language: @total Nodes', [
          '@language' => $language,
          '@total' => $content_type_info[$i]->total,
        ]) : $this
          ->t('0 Nodes');
      }
      else {

        // Adding text with total nodes.
        $total_nodes = $content_type_info[$i]->total ? $this
          ->formatPlural($content_type_info[$i]->total, '@total Node', '@total Nodes', [
          '@total' => $content_type_info[$i]->total,
        ]) : $this
          ->t('0 Nodes');
      }

      // Adding the total nodes information.
      $content_types[$conten_type][$i]->total_nodes = $total_nodes;
    }
  }
}