Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176

This commit is contained in:
Pantheon Automation 2015-08-17 17:00:26 -07:00 committed by Greg Anderson
commit 9921556621
13277 changed files with 1459781 additions and 0 deletions

View file

@ -0,0 +1,33 @@
<?php
/**
* @file
* Contains \Drupal\forum\Plugin\Block\ActiveTopicsBlock.
*/
namespace Drupal\forum\Plugin\Block;
/**
* Provides an 'Active forum topics' block.
*
* @Block(
* id = "forum_active_block",
* admin_label = @Translation("Active forum topics"),
* category = @Translation("Lists (Views)")
* )
*/
class ActiveTopicsBlock extends ForumBlockBase {
/**
* {@inheritdoc}
*/
protected function buildForumQuery() {
return db_select('forum_index', 'f')
->fields('f')
->addTag('node_access')
->addMetaData('base_table', 'forum_index')
->orderBy('f.last_comment_timestamp', 'DESC')
->range(0, $this->configuration['block_count']);
}
}

View file

@ -0,0 +1,101 @@
<?php
/**
* @file
* Contains \Drupal\forum\Plugin\Block\ForumBlockBase.
*/
namespace Drupal\forum\Plugin\Block;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Url;
/**
* Provides a base class for Forum blocks.
*/
abstract class ForumBlockBase extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$result = $this->buildForumQuery()->execute();
$elements = array();
if ($node_title_list = node_title_list($result)) {
$elements['forum_list'] = $node_title_list;
$elements['forum_more'] = array(
'#type' => 'more_link',
'#url' => Url::fromRoute('forum.index'),
'#attributes' => array('title' => $this->t('Read the latest forum topics.')),
);
}
return $elements;
}
/**
* Builds the select query to use for this forum block.
*
* @return \Drupal\Core\Database\Query\Select
* A Select object.
*/
abstract protected function buildForumQuery();
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array(
'properties' => array(
'administrative' => TRUE,
),
'block_count' => 5,
);
}
/**
* {@inheritdoc}
*/
protected function blockAccess(AccountInterface $account) {
return AccessResult::allowedIfHasPermission($account, 'access content');
}
/**
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
$range = range(2, 20);
$form['block_count'] = array(
'#type' => 'select',
'#title' => $this->t('Number of topics'),
'#default_value' => $this->configuration['block_count'],
'#options' => array_combine($range, $range),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state) {
$this->configuration['block_count'] = $form_state->getValue('block_count');
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return ['user.node_grants:view'];
}
/**
* {@inheritdoc}
*/
public function getCacheTags() {
return ['node_list'];
}
}

View file

@ -0,0 +1,32 @@
<?php
/**
* @file
* Contains \Drupal\forum\Plugin\Block\NewTopicsBlock.
*/
namespace Drupal\forum\Plugin\Block;
/**
* Provides a 'New forum topics' block.
*
* @Block(
* id = "forum_new_block",
* admin_label = @Translation("New forum topics"),
* category = @Translation("Lists (Views)")
* )
*/
class NewTopicsBlock extends ForumBlockBase {
/**
* {@inheritdoc}
*/
protected function buildForumQuery() {
return db_select('forum_index', 'f')
->fields('f')
->addTag('node_access')
->addMetaData('base_table', 'forum_index')
->orderBy('f.created', 'DESC')
->range(0, $this->configuration['block_count']);
}
}

View file

@ -0,0 +1,24 @@
<?php
/**
* @file
* Contains \Drupal\forum\Plugin\Validation\Constraint\ForumLeafConstraint.
*/
namespace Drupal\forum\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
/**
* Checks that the node is assigned only a "leaf" term in the forum taxonomy.
*
* @Constraint(
* id = "ForumLeaf",
* label = @Translation("Forum leaf", context = "Validation"),
* )
*/
class ForumLeafConstraint extends Constraint {
public $selectForum = 'Select a forum.';
public $noLeafMessage = 'The item %forum is a forum container, not a forum. Select one of the forums below instead.';
}

View file

@ -0,0 +1,39 @@
<?php
/**
* @file
* Contains \Drupal\forum\Plugin\Validation\Constraint\ForumLeafConstraintValidator.
*/
namespace Drupal\forum\Plugin\Validation\Constraint;
use Drupal\Component\Utility\Unicode;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* Validates the ForumLeaf constraint.
*/
class ForumLeafConstraintValidator extends ConstraintValidator {
/**
* {@inheritdoc}
*/
public function validate($items, Constraint $constraint) {
$item = $items->first();
if (!isset($item)) {
return NULL;
}
// Verify that a term has been selected.
if (!$item->entity) {
$this->context->addViolation($constraint->selectForum);
}
// The forum_container flag must not be set.
if (!empty($item->entity->forum_container->value)) {
$this->context->addViolation($constraint->noLeafMessage, array('%forum' => $item->entity->getName()));
}
}
}