You are here

class OnlyOnePrintDrush in Allow a content type only once (Only One) 8

Class OnlyOnePrintDrush.

Hierarchy

Expanded class hierarchy of OnlyOnePrintDrush

3 files declare their use of OnlyOnePrintDrush
onlyone.drush.inc in ./onlyone.drush.inc
Drush commands related to the Only One module.
OnlyOnePrintDrushTest.php in tests/src/Unit/OnlyOnePrintDrushTest.php
OnlyOneTest.php in tests/src/Unit/OnlyOneTest.php

File

src/OnlyOnePrintDrush.php, line 10

Namespace

Drupal\onlyone
View source
class OnlyOnePrintDrush implements OnlyOnePrintStrategyInterface {
  use StringTranslationTrait;

  /**
   * Green color for text used in drush commands.
   */
  const GREEN_OUTPUT = "\33[1;32;40m\33[1m%s\33[0m";

  /**
   * Red color for text used in drush commands.
   */
  const RED_OUTPUT = "\33[31;40m\33[1m%s\33[0m";

  /**
   * {@inheritdoc}
   */
  public function getContentTypesListForPrint(array $content_types) {
    $list = [];

    // Iterating over each content type.
    foreach ($content_types as $content_type => $content_type_info) {
      $cant = count($content_type_info);

      // Iterating over each language.
      for ($i = 0; $i < $cant; $i++) {

        // Example for multilingual sites:
        // Article (En: 7 Nodes, Fr: 5 Nodes, Not specified: 2 Nodes).
        // Example for non multilingual sites:
        // Article (3 Nodes).
        $list[$content_type] = $content_type_info[$i]->name . ' (' . implode(', ', array_column($content_type_info, 'total_nodes')) . ')';
        $list[$content_type] .= $content_type_info[$i]->configured ? ' ' . sprintf(self::GREEN_OUTPUT, $this
          ->t('Configured')) : '';
      }
    }
    return $list;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OnlyOnePrintDrush::getContentTypesListForPrint public function Return a list of content types for print. Overrides OnlyOnePrintStrategyInterface::getContentTypesListForPrint
OnlyOnePrintDrush::GREEN_OUTPUT constant Green color for text used in drush commands.
OnlyOnePrintDrush::RED_OUTPUT constant Red color for text used in drush commands.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.