Last active
August 29, 2015 13:57
-
-
Save sdboyer/9879940 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class BlockNGInterface extends HtmlFragmentInterface, ConfigurablePluginInterface, PluginFormInterface, PluginInspectionInterface /*, CacheableInterface */ { | |
public function access(AccountInterface $account); | |
public function getMachineNameSuggestion(); | |
// public function build(); // DIE DIE DIE | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Trait for blocks that are dependent on render arrays. | |
* | |
* AKA, "The Block Demultiplexer" | |
*/ | |
trait RenderArrayBasedBlock /* implements BlockNGInterface */ { | |
// Optionally override this if the block wants to have a different way | |
// of getting the title | |
public function getTitle() { | |
$r = $this->render(); | |
return $r['#title']; | |
} | |
public function getContent() { | |
$r = $this->render(); | |
return $r['#content']; | |
} | |
public function getMeta() { | |
$r = $this->render(); | |
// TODO this isn't so well-established right now | |
return $r['#meta']; | |
} | |
public function getAssets() { | |
// a version of drupal_process_attached() that returns found assets instead | |
// of adding them to the global static caches | |
return drupal_collect_attached($this->render()); | |
} | |
// Ensure we the render array is built only once | |
final protected function render() { | |
if (!isset($this->render)) { | |
$this->render = $this->build(); | |
} | |
return $this->render; | |
} | |
abstract protected function build(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface HtmlFragmentInterface { | |
public function getTitle(); | |
public function getContent(); | |
public function getMeta(); | |
public function getAssets(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment