class DisplayManager

Same name in other branches
  1. 3.x modules/phpunit_example/src/DisplayManager.php \Drupal\phpunit_example\DisplayManager

An example class to demonstrate unit testing.

Think of this class as a class that collects DisplayInfoInterface objects, because that's what it is. It also might go on to one day display lists of info about these info objects.

But it never will, because it's just an example class.

Part of the PHPUnit Example module.

Hierarchy

Expanded class hierarchy of DisplayManager

Related topics

1 file declares its use of DisplayManager
DisplayManagerTest.php in modules/phpunit_example/tests/src/Unit/DisplayManagerTest.php

File

modules/phpunit_example/src/DisplayManager.php, line 18

Namespace

Drupal\phpunit_example
View source
class DisplayManager {
    
    /**
     * DisplayInfoInterface items.
     *
     * @var array
     */
    protected $items;
    
    /**
     * Add a displayable item.
     *
     * @param DisplayInfoInterface $item
     *   The item to add.
     */
    public function addDisplayableItem(DisplayInfoInterface $item) {
        $this->items[$item->getDisplayName()] = $item;
    }
    
    /**
     * A count of how many items exist.
     *
     * @return int
     *   The number of items that exist.
     */
    public function countDisplayableItems() {
        return count($this->items);
    }
    
    /**
     * All displayable items.
     *
     * @return array
     *   The displayable items.
     */
    public function displayableItems() {
        return $this->items;
    }
    
    /**
     * Find an item by its name.
     *
     * @param string $name
     *   The name to find.
     *
     * @return DisplayInfoInterface|null
     *   The found item, or NULL if none is found.
     */
    public function item($name) {
        if (isset($this->items[$name])) {
            return $this->items[$name];
        }
        return NULL;
    }

}

Members

Title Sort descending Modifiers Object type Summary
DisplayManager::$items protected property DisplayInfoInterface items.
DisplayManager::addDisplayableItem public function Add a displayable item.
DisplayManager::countDisplayableItems public function A count of how many items exist.
DisplayManager::displayableItems public function All displayable items.
DisplayManager::item public function Find an item by its name.