Version 1
[yaffs-website] / web / core / modules / system / tests / modules / plugin_test / src / Plugin / plugin_test / mock_block / MockMenuBlock.php
1 <?php
2
3 namespace Drupal\plugin_test\Plugin\plugin_test\mock_block;
4
5 /**
6  * Mock implementation of a menu block plugin used by Plugin API unit tests.
7  *
8  * @see \Drupal\plugin_test\Plugin\MockBlockManager
9  */
10 class MockMenuBlock {
11
12   /**
13    * The title to display when rendering this block instance.
14    *
15    * @var string
16    */
17   protected $title;
18
19   /**
20    * The number of menu levels deep to render.
21    *
22    * @var int
23    */
24   protected $depth;
25
26   public function __construct($title = '', $depth = 0) {
27     $this->title = $title;
28     $this->depth = $depth;
29   }
30
31   /**
32    * Returns the content to display.
33    */
34   public function getContent() {
35     // Since this is a mock object, we just return some HTML of the desired
36     // nesting level. For depth=2, this returns:
37     // '<ul><li>1<ul><li>1.1</li></ul></li></ul>'.
38     $content = '';
39     for ($i = 0; $i < $this->depth; $i++) {
40       $content .= '<ul><li>' . implode('.', array_fill(0, $i + 1, '1'));
41     }
42     for ($i = 0; $i < $this->depth; $i++) {
43       $content .= '</li></ul>';
44     }
45     return $content;
46   }
47
48 }