You are here

public function OnlyOne::getNotAvailableContentTypesSummarized in Allow a content type only once (Only One) 8

Return the not available content types with their number of nodes.

Return value

array An array of objects with the not available content types keyed by content type machine name.

Overrides OnlyOneInterface::getNotAvailableContentTypesSummarized

1 call to OnlyOne::getNotAvailableContentTypesSummarized()
OnlyOne::getNotAvailableContentTypesForPrint in src/OnlyOne.php
Return a list of non-available content types for print.

File

src/OnlyOne.php, line 313

Class

OnlyOne
Class OnlyOne.

Namespace

Drupal\onlyone

Code

public function getNotAvailableContentTypesSummarized() {

  // Multilingual site?
  if ($this->languageManager
    ->isMultilingual()) {

    // Looking for content types that doesn't have more than 1 node
    // in any language.
    $query = "SELECT DISTINCT node.type,\n                                node_field_data.langcode AS language,\n                                COUNT(node.nid) AS total\n                FROM {node} node\n                JOIN {node_field_data} node_field_data USING(nid)\n                WHERE node.type IN\n                    (SELECT DISTINCT node.type\n                     FROM {node} node\n                     JOIN {node_field_data} node_field_data USING(nid)\n                     GROUP BY type,\n                              node_field_data.langcode\n                     HAVING COUNT(nid) > 1)\n                GROUP BY node.type,\n                         language\n                ORDER BY node.type ASC";
  }
  else {

    // If the site is not multilingual we have only one language.
    $query = "SELECT type,\n                       COUNT(nid) AS total\n                FROM {node}\n                GROUP BY type\n                HAVING COUNT(nid) > 1\n                ORDER BY type ASC";
  }

  // Executing the query.
  $result = $this->connection
    ->query($query);

  // Getting the information keyed by content type machine name.
  $content_types = $result
    ->fetchAll(\PDO::FETCH_GROUP);

  // Adding content type name and other information.
  $this
    ->addAditionalInfoToContentTypes($content_types);
  return $content_types;
}