
Upgrade the commons modules to version 3.15, see release notes here: https://www.drupal.org/node/2292227 The upgrade contains the following custom patches: - 0001-utility-links-block-install-theme.patch Change-Id: Ia3f385d56171d3ea0983fb2c39916dd176e0af6d
112 lines
3.6 KiB
Plaintext
112 lines
3.6 KiB
Plaintext
<?php
|
|
/**
|
|
* @file
|
|
* Code for the Commons Posts feature.
|
|
*/
|
|
|
|
include_once 'commons_posts.features.inc';
|
|
|
|
/**
|
|
* Implements hook_form_BASE_FORM_ID_alter().
|
|
*/
|
|
function commons_posts_form_node_form_alter(&$form, &$form_state, $form_id) {
|
|
$node = $form['#node'];
|
|
|
|
list(, , $bundle) = entity_extract_ids('node', $node);
|
|
|
|
if ($bundle == 'post' && empty($node->nid)) {
|
|
drupal_set_title(t('Create a post'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_form_FROM_ID_alter().
|
|
*/
|
|
function commons_posts_form_commons_bw_partial_node_form_alter(&$form, &$form_state) {
|
|
if (empty($form['#entity']) || $form['#entity']->type != 'post') {
|
|
return;
|
|
}
|
|
|
|
$form['title']['#markup'] = t('Create a post');
|
|
|
|
$language = $form['body']['#language'];
|
|
$form['body'][$language][0]['#title_display'] = 'invisible';
|
|
$form['body'][$language][0]['#required'] = TRUE;
|
|
$form['body'][$language][0]['#placeholder'] = t("What's on your mind?");
|
|
$form['body'][$language][0]['#resizable'] = FALSE;
|
|
|
|
// Set fields as hideable so the forms can be compacted.
|
|
$form['body']['#attributes']['class'][] = 'trigger-field';
|
|
foreach (array('field_media', 'field_image', 'og_group_ref', 'choice_wrapper', 'actions') as $field) {
|
|
if (isset($form[$field])) {
|
|
$form[$field]['#attributes']['class'][] = 'hideable-field';
|
|
}
|
|
}
|
|
|
|
$form['actions']['submit']['#value'] = t('Post');
|
|
$form['#pre_render'][] = 'commons_posts_form_commons_bw_partial_node_form_after_build';
|
|
}
|
|
|
|
/**
|
|
* After-build call-back.
|
|
* See commons_posts_form_commons_bw_partial_node_form_alter().
|
|
*/
|
|
function commons_posts_form_commons_bw_partial_node_form_after_build($form) {
|
|
$language = $form['body']['#language'];
|
|
$form['body'][$language][0]['#pre_render'] = array();
|
|
$form['body'][$language][0]['format']['#access'] = FALSE;
|
|
$form['body'][$language][0]['value']['#rows'] = 3;
|
|
|
|
return $form;
|
|
}
|
|
|
|
|
|
/**
|
|
* Implements commons_activity_streams_message_selection_alter().
|
|
*/
|
|
function commons_posts_commons_activity_streams_message_selection_alter(&$message_type, $hook, $node) {
|
|
// Use a "User posted [title]" format activity stream message.
|
|
if ($hook == 'node_insert' && $node->type == 'post') {
|
|
$message_type = 'commons_posts_post_created';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_strongarm_alter().
|
|
*/
|
|
function commons_posts_strongarm_alter(&$items) {
|
|
// Expose the Post content type for 'liking' via the Commons_like module
|
|
// by altering the configuration for the Rate.module widget that it provides.
|
|
if (!empty($items['rate_widgets']->value)) {
|
|
foreach($items['rate_widgets']->value as $key => $widget) {
|
|
if ($widget->name == 'commons_like') {
|
|
if (!in_array('post', $items['rate_widgets']->value[$key]->node_types)) {
|
|
$items['rate_widgets']->value[$key]->node_types[] = 'post';
|
|
}
|
|
if (!in_array('post', $items['rate_widgets']->value[$key]->comment_types)) {
|
|
$items['rate_widgets']->value[$key]->comment_types[] = 'post';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Expose the post content type for integration with Commons Radioactivity
|
|
// and Commons Groups.
|
|
foreach (array('commons_radioactivity_entity_types', 'commons_groups_entity_types') as $key) {
|
|
if (isset($items[$key])) {
|
|
$items[$key]->value['node']['post'] = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_views_pre_render().
|
|
*/
|
|
function commons_posts_views_pre_render(&$view) {
|
|
// Improve the browsing widget empty text when displayed outside of a group.
|
|
// TODO: Enable og_context and check group context instead of looking for an
|
|
// empty first argument.
|
|
if (empty($view->args[0]) && $view->name == 'commons_bw_posts') {
|
|
$view->display_handler->handlers['empty']['area']->options['content'] = t('No posts have been created.');
|
|
}
|
|
}
|