Loading src/Entity/AuthorPane.php +23 −9 Changes for src/Entity/AuthorPane.php: 23 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ namespace Drupal\author_pane\Entity; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\user\UserInterface; /** * Defines an AuthorPane configuration entity class. Loading Loading @@ -89,14 +90,21 @@ class AuthorPane extends ConfigEntityBase { } /** * Sets the author for this author pane. * Sets the user account whose information is displayed on the pane. * * @param $author * UID or full user object. * @param \Drupal\user\UserInterface $author */ public function setAuthor($author) { // @TODO: Get the real author object. $this->author = user_load(1); public function setAuthor(UserInterface $author) { $this->author = $author; } /** * Gets the user account whose information is displayed on the pane. * * @return \Drupal\user\Entity\User */ public function getAuthor() { return $this->author; } /** Loading @@ -105,18 +113,24 @@ class AuthorPane extends ConfigEntityBase { * @return string */ public function display() { $author = $this->getAuthor(); if ($author instanceof UserInterface) { $author_pane_data = $this->datumPluginManager->getDefinitions(); $content = ''; foreach ($author_pane_data as $datum_array) { // Make an instance of the datum. $datum = $this->datumPluginManager->createInstance($datum_array['id']); $datum->setAuthor($this->author); $datum->setAuthor($author); // @TODO: Theme this properly with a template. $content .= $datum->output(); } return $content; } else { $content = $this.t('No author set.'); } return $content; } } src/Plugin/Block/AuthorPaneBlock.php +30 −3 Changes for src/Plugin/Block/AuthorPaneBlock.php: 30 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ use Drupal\author_pane\Entity\AuthorPane; * @Block( * id = "author_pane_block", * admin_label = @Translation("Author Information"), * context = { * "node" = @ContextDefinition("entity:node", required = FALSE) * } * ) */ class AuthorPaneBlock extends BlockBase { Loading @@ -39,14 +42,13 @@ class AuthorPaneBlock extends BlockBase { $this->authorPaneManager = \Drupal::service('authorpane.manager'); } /** * {@inheritdoc} */ public function blockForm($form, FormStateInterface $form_state) { // @TODO: Replace this with list of author panes. $options = array("default_pane"); $options = array('authorpane' => 'Author Pane'); $config = $this->getConfiguration(); Loading @@ -67,19 +69,44 @@ class AuthorPaneBlock extends BlockBase { $this->configuration['author_pane'] = $form_state->getValue('author_pane'); } /** * {@inheritdoc} */ public function build() { $block = array(); // Try to determine the author from context. $author = $this->findAuthor(); // If we have no author, we can't build the pane. if (!is_null($author)) { $config = $this->getConfiguration(); $this->authorPane = $this->authorPaneManager->load($config['author_pane']); $this->authorPane->setAuthor($author); $content = $this->authorPane->display(); // @TODO: More advanced theming on the block? $block = array('#markup' => $content); } return $block; } private function findAuthor() { $author = NULL; // First, see if there is a node context we can pull the author from. $node = $this->getContextValue('node'); if (!is_null($node)) { $author = $node->getOwner(); } else { // @TODO: Figure out how to get the user from URL on profile pages. // @TODO: Figure out how to make this work with Panels, etc. } return $author; } } Loading
src/Entity/AuthorPane.php +23 −9 Changes for src/Entity/AuthorPane.php: 23 added lines, 9 removed lines. Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ namespace Drupal\author_pane\Entity; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\user\UserInterface; /** * Defines an AuthorPane configuration entity class. Loading Loading @@ -89,14 +90,21 @@ class AuthorPane extends ConfigEntityBase { } /** * Sets the author for this author pane. * Sets the user account whose information is displayed on the pane. * * @param $author * UID or full user object. * @param \Drupal\user\UserInterface $author */ public function setAuthor($author) { // @TODO: Get the real author object. $this->author = user_load(1); public function setAuthor(UserInterface $author) { $this->author = $author; } /** * Gets the user account whose information is displayed on the pane. * * @return \Drupal\user\Entity\User */ public function getAuthor() { return $this->author; } /** Loading @@ -105,18 +113,24 @@ class AuthorPane extends ConfigEntityBase { * @return string */ public function display() { $author = $this->getAuthor(); if ($author instanceof UserInterface) { $author_pane_data = $this->datumPluginManager->getDefinitions(); $content = ''; foreach ($author_pane_data as $datum_array) { // Make an instance of the datum. $datum = $this->datumPluginManager->createInstance($datum_array['id']); $datum->setAuthor($this->author); $datum->setAuthor($author); // @TODO: Theme this properly with a template. $content .= $datum->output(); } return $content; } else { $content = $this.t('No author set.'); } return $content; } }
src/Plugin/Block/AuthorPaneBlock.php +30 −3 Changes for src/Plugin/Block/AuthorPaneBlock.php: 30 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ use Drupal\author_pane\Entity\AuthorPane; * @Block( * id = "author_pane_block", * admin_label = @Translation("Author Information"), * context = { * "node" = @ContextDefinition("entity:node", required = FALSE) * } * ) */ class AuthorPaneBlock extends BlockBase { Loading @@ -39,14 +42,13 @@ class AuthorPaneBlock extends BlockBase { $this->authorPaneManager = \Drupal::service('authorpane.manager'); } /** * {@inheritdoc} */ public function blockForm($form, FormStateInterface $form_state) { // @TODO: Replace this with list of author panes. $options = array("default_pane"); $options = array('authorpane' => 'Author Pane'); $config = $this->getConfiguration(); Loading @@ -67,19 +69,44 @@ class AuthorPaneBlock extends BlockBase { $this->configuration['author_pane'] = $form_state->getValue('author_pane'); } /** * {@inheritdoc} */ public function build() { $block = array(); // Try to determine the author from context. $author = $this->findAuthor(); // If we have no author, we can't build the pane. if (!is_null($author)) { $config = $this->getConfiguration(); $this->authorPane = $this->authorPaneManager->load($config['author_pane']); $this->authorPane->setAuthor($author); $content = $this->authorPane->display(); // @TODO: More advanced theming on the block? $block = array('#markup' => $content); } return $block; } private function findAuthor() { $author = NULL; // First, see if there is a node context we can pull the author from. $node = $this->getContextValue('node'); if (!is_null($node)) { $author = $node->getOwner(); } else { // @TODO: Figure out how to get the user from URL on profile pages. // @TODO: Figure out how to make this work with Panels, etc. } return $author; } }