View source
<?php
include_once 'panopoly_widgets.features.inc';
include_once 'panopoly_widgets.spotlight.inc';
define('PANOPOLY_WIDGETS_FILE_EXTENSIONS_DEFAULT', 'txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp');
function panopoly_widgets_init() {
if (arg(0) == 'media' && arg(1) == 'browser') {
if ($GLOBALS['theme'] != 'seven') {
drupal_add_css(drupal_get_path('theme', 'seven') . '/reset.css', array(
'basename' => 'seven_reset',
'group' => CSS_THEME,
));
drupal_add_css(drupal_get_path('theme', 'seven') . '/style.css', array(
'basename' => 'seven_style',
'group' => CSS_THEME,
));
}
drupal_add_css(drupal_get_path('module', 'panopoly_widgets') . '/panopoly-widgets-media-browser.css', array(
'group' => CSS_THEME,
));
}
}
function panopoly_widgets_apps_app_info() {
return array(
'configure form' => 'panopoly_widgets_configure_form',
);
}
function panopoly_widgets_configure_form($form, &$form_state) {
$form = array();
$file_extensions = variable_get('panopoly_widgets_file_extensions', PANOPOLY_WIDGETS_FILE_EXTENSIONS_DEFAULT);
$file_extensions = str_replace(' ', ', ', $file_extensions);
$form['panopoly_widgets_file_extensions'] = array(
'#title' => t('Allowed file extensions in file widgets.'),
'#type' => 'textfield',
'#default_value' => $file_extensions,
'#element_validate' => array(
'_file_generic_settings_extensions',
),
'#description' => t('Separate extensions with a space or comma and do not include the leading dot.'),
);
$form['panopoly_widgets_spotlight_pause_play_buttons'] = array(
'#title' => t('Add pause/play button to all spotlight widgets.'),
'#type' => 'checkbox',
'#default_value' => variable_get('panopoly_widgets_spotlight_pause_play_buttons', 1),
'#description' => t('The button will appear under to the slide numbers. Helps with accessibility.'),
);
$form = system_settings_form($form);
$form['#submit'][] = 'panopoly_widgets_configure_form_submit';
return $form;
}
function panopoly_widgets_configure_form_submit($form, &$form_state) {
if ($file_instance = field_info_instance('fieldable_panels_pane', 'field_basic_file_file', 'basic_file')) {
$file_extensions = $form_state['values']['panopoly_widgets_file_extensions'];
$file_instance['settings']['file_extensions'] = $file_extensions;
field_update_instance($file_instance);
}
}
function panopoly_widgets_field_default_field_instances_alter(&$instances) {
if (isset($instances['fieldable_panels_pane-basic_file-field_basic_file_file'])) {
$file_extensions = variable_get('panopoly_widgets_file_extensions', PANOPOLY_WIDGETS_FILE_EXTENSIONS_DEFAULT);
$instances['fieldable_panels_pane-basic_file-field_basic_file_file']['settings']['file_extensions'] = $file_extensions;
}
if (isset($instances['fieldable_panels_pane-image-field_basic_image_link'])) {
if (!module_exists('linkit')) {
$instances['fieldable_panels_pane-image-field_basic_image_link']['settings']['linkit']['enable'] = 0;
$instances['fieldable_panels_pane-image-field_basic_image_link']['settings']['linkit']['profile'] = NULL;
}
}
}
function panopoly_widgets_page_build(&$page) {
drupal_add_js(drupal_get_path('module', 'panopoly_widgets') . '/panopoly-widgets.js', array(
'scope' => 'footer',
));
drupal_add_js(drupal_get_path('module', 'panopoly_widgets') . '/panopoly-widgets-spotlight.js', array(
'scope' => 'footer',
));
}
function panopoly_widgets_ctools_plugin_directory($module, $plugin) {
return 'plugins/' . $plugin;
}
function panopoly_widgets_ctools_content_subtype_alter(&$subtype, &$plugin) {
if ($plugin['module'] == 'menu_block' && $subtype['menu_title'] == 'Main menu') {
$subtype['category'][0] = t('Custom');
$subtype['top level'] = TRUE;
$subtype['title'] = t('Add submenu');
$subtype['icon'] = drupal_get_path('module', 'panopoly_widgets') . '/images/icon_submenu.png';
$subtype['admin css'] = array(
drupal_get_path('module', 'menu_block') . '/menu-block-admin.css',
);
$subtype['admin js'] = array(
drupal_get_path('module', 'menu_block') . '/menu-block.js',
);
$subtype['defaults']['expanded_max_depth'] = 0;
}
if ($plugin['module'] == 'views_content' && $subtype['title'] == 'Piece of Content') {
$subtype['category'][0] = t('Custom');
$subtype['top level'] = TRUE;
$subtype['title'] = t('Add content item');
$subtype['icon'] = drupal_get_path('module', 'panopoly_widgets') . '/images/icon_content_item.png';
}
if ($plugin['module'] == 'views_content' && $subtype['title'] == 'List of Content') {
$subtype['category'][0] = t('Custom');
$subtype['top level'] = TRUE;
$subtype['title'] = t('Add content list');
$subtype['icon'] = drupal_get_path('module', 'panopoly_widgets') . '/images/icon_content_list.png';
}
if ($subtype['category'] == 'Node' || $subtype['category'] == 'Entity') {
$subtype['category'] = t('Page Content');
}
if ($subtype['category'] == 'User') {
$subtype['category'] = t('User Content');
}
if ($subtype['category'] == 'Taxonomy_term' || $subtype['category'] == 'Taxonomy term') {
$subtype['category'] = t('Category Content');
}
if ($subtype['category'] == 'Form') {
$subtype['category'] = t('Form Content');
}
}
function panopoly_widgets_ctools_plugin_post_alter(&$plugin, &$info) {
if ($info['module'] == 'ctools' && $info['type'] == 'content_types' && $plugin['module'] == 'fieldable_panels_panes' && $plugin['name'] == 'fieldable_panels_pane') {
$plugin['original render callback'] = $plugin['render callback'];
$plugin['render callback'] = 'panopoly_widgets_fieldable_panels_pane_render';
}
}
function panopoly_widgets_get_required_file_fields($bundle) {
$required_file_fields = array();
$field_instances = field_info_instances('fieldable_panels_pane', $bundle);
foreach ($field_instances as $field_name => $field_instance) {
$field_info = field_info_field($field_name);
if (in_array($field_info['type'], array(
'file',
'image',
)) && !empty($field_instance['required'])) {
$required_file_fields[] = $field_name;
}
}
return $required_file_fields;
}
function panopoly_widgets_fieldable_panels_pane_render($subtype, $conf, $panels_args = array(), $context = array()) {
ctools_include('content');
$plugin = ctools_get_content_type('fieldable_panels_pane');
$subtype_info = ctools_content_get_subtype($plugin, $subtype);
if (!empty($subtype_info)) {
$entity = fieldable_panels_panes_load_from_subtype($subtype);
$required_file_fields = panopoly_widgets_get_required_file_fields($entity->bundle);
$missing_required = FALSE;
if (!empty($required_file_fields)) {
foreach ($required_file_fields as $required_file_field) {
$items = field_get_items('fieldable_panels_pane', $entity, $required_file_field);
if (empty($items[0]) || empty($items[0]['fid']) || !file_load($items[0]['fid'])) {
$missing_required = TRUE;
break;
}
}
}
if ($missing_required) {
return NULL;
}
$original_render_callback = $plugin['original render callback'];
return $original_render_callback($subtype, $conf, $panels_args, $context);
}
}
function panopoly_widgets_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'menu_block_menu_tree_content_type_edit_form') {
$form['admin_title']['#access'] = FALSE;
$form['depth']['#access'] = FALSE;
$form['display_options']['#default_value'] = 'advanced';
$form['display_options']['#access'] = FALSE;
$form['title_link']['#access'] = FALSE;
$form['buttons']['#prefix'] = '<div class="menu-block-ctools-buttons">';
$form['sort']['#access'] = FALSE;
$form['expanded_max_depth'] = array(
'#type' => 'select',
'#title' => t('Maximum expanded depth'),
'#weight' => 9,
'#options' => array(
'1' => t('Only 1 level'),
'2' => t('Only 2 levels'),
'3' => t('Only 3 levels'),
'4' => t('Only 4 levels'),
'5' => t('Only 5 levels'),
'6' => t('Only 6 levels'),
'7' => t('Only 7 levels'),
'8' => t('Only 8 levels'),
'9' => t('Only 9 levels'),
'0' => t('Expand all children'),
),
'#default_value' => isset($form_state['conf']['expanded_max_depth']) ? $form_state['conf']['expanded_max_depth'] : 0,
'#states' => array(
'visible' => array(
':input[name="expanded"]' => array(
'checked' => TRUE,
),
),
),
);
$form['expanded']['#weight'] = 8;
$form['expanded']['#title'] = t('<strong>Expand children</strong> of this tree.');
if (!empty($form['display_empty'])) {
$form['display_empty']['#access'] = FALSE;
}
}
if ($form_id == 'fieldable_panels_panes_fieldable_panels_pane_content_type_edit_form') {
if ($form_state['entity']->reusable && $form_state['op'] == 'add') {
if (fieldable_panels_panes_access('update', $form_state['entity'])) {
$form = fieldable_panels_panes_entity_edit_form($form, $form_state);
$form_state['no update entity'] = FALSE;
}
else {
$form['message']['#markup'] = '<p>' . t("You don't have permission to edit this widget.") . '</p>';
return;
}
}
$form['#pre_render'][] = 'panopoly_widgets_fieldable_panel_pane_pre_render';
$form['revision']['revision']['#type'] = 'value';
$form['revision']['log']['#access'] = FALSE;
$form['widget_settings']['#type'] = 'fieldset';
$form['widget_settings']['#title'] = t('General Settings');
$form['title']['#attributes']['placeholder'] = $form['title']['#title'];
$form['title']['#title_display'] = 'invisible';
$form['widget_settings']['title'] = $form['title'];
if (!(module_exists('title') && isset($form['title']['#field_replacement']) && $form['title']['#field_replacement'])) {
unset($form['title']);
}
$form['widget_settings']['link'] = $form['link'];
unset($form['link']);
$form['reusable']['#title'] = t('Reusable Settings');
$form['reusable']['#type'] = 'fieldset';
$form['reusable']['#process'] = array(
'ctools_dependent_process',
);
$form['reusable']['#id'] = 'reusable-settings';
$form['reusable']['category']['#value'] = t('Reusable Content');
$form['reusable']['category']['#type'] = 'value';
$form['reusable']['admin_description']['#access'] = FALSE;
$form['reusable']['warning']['#dependency'] = array(
'edit-reusable' => array(
1,
),
);
$form['reusable']['warning']['#prefix'] = '<div id="reusable-wrapper">';
$form['reusable']['warning']['#suffix'] = '</div>';
$form['reusable']['warning']['#type'] = 'item';
$form['reusable']['warning']['#markup'] = '<div class="description">' . t('Note: This item is reusable! Any changes made will be applied globally.') . '</div>';
}
if (!empty($form['field_basic_table_table'])) {
$form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['import']['#access'] = FALSE;
$form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['#collapsible'] = FALSE;
$form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['#collapsed'] = FALSE;
$form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['count_cols']['#field_prefix'] = $form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['count_cols']['#title'] . '? ';
$form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['count_cols']['#title'] = '';
$form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['count_rows']['#field_prefix'] = $form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['count_rows']['#title'] . '? ';
$form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['count_rows']['#title'] = '';
}
}
function panopoly_widgets_fieldable_panel_pane_pre_render($element) {
$element['content_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Content Settings'),
'#weight' => 1,
);
foreach ($element as $key => $value) {
if (substr($key, 0, 6) == 'field_' || $key == 'body') {
$element['content_settings'][$key] = $value;
unset($element[$key]);
}
}
return $element;
}
function panopoly_widgets_entity_info_alter(&$entity_info) {
$entity_info['fieldable_panels_pane']['bundles']['quick_links'] = array(
'label' => t('Add links'),
'description' => t('Add links'),
'pane category' => t('Custom'),
'pane top level' => TRUE,
'pane icon' => drupal_get_path('module', 'panopoly_widgets') . '/images/icon_link.png',
'admin' => array(
'path' => 'admin/structure/fieldable-panels-panes/%fieldable_panels_panes_type',
'bundle argument' => 3,
'real path' => 'admin/structure/fieldable-panels-panes/quick-links',
'access arguments' => array(
'administer fieldable panels panes',
),
),
);
$entity_info['fieldable_panels_pane']['bundles']['basic_file'] = array(
'label' => t('Add file'),
'description' => t('Add file'),
'pane category' => t('Custom'),
'pane top level' => TRUE,
'pane icon' => drupal_get_path('module', 'panopoly_widgets') . '/images/icon_file.png',
'admin' => array(
'path' => 'admin/structure/fieldable-panels-panes/%fieldable_panels_panes_type',
'bundle argument' => 3,
'real path' => 'admin/structure/fieldable-panels-panes/basic-file',
'access arguments' => array(
'administer fieldable panels panes',
),
),
);
$entity_info['fieldable_panels_pane']['bundles']['image'] = array(
'label' => t('Add image'),
'description' => t('Add image'),
'pane category' => t('Custom'),
'pane top level' => TRUE,
'pane icon' => drupal_get_path('module', 'panopoly_widgets') . '/images/icon_image.png',
'admin' => array(
'path' => 'admin/structure/fieldable-panels-panes/%fieldable_panels_panes_type',
'bundle argument' => 3,
'real path' => 'admin/structure/fieldable-panels-panes/image',
'access arguments' => array(
'administer fieldable panels panes',
),
),
);
$entity_info['fieldable_panels_pane']['bundles']['text'] = array(
'label' => t('Add text'),
'description' => t('Add text'),
'pane category' => t('Custom'),
'pane top level' => TRUE,
'pane icon' => drupal_get_path('module', 'panopoly_widgets') . '/images/icon_text.png',
'admin' => array(
'path' => 'admin/structure/fieldable-panels-panes/%fieldable_panels_panes_type',
'bundle argument' => 3,
'real path' => 'admin/structure/fieldable-panels-panes/text',
'access arguments' => array(
'administer fieldable panels panes',
),
),
);
$entity_info['fieldable_panels_pane']['bundles']['map'] = array(
'label' => t('Add map'),
'description' => t('Add map'),
'pane category' => t('Custom'),
'pane top level' => TRUE,
'pane icon' => drupal_get_path('module', 'panopoly_widgets') . '/images/icon_map.png',
'admin' => array(
'path' => 'admin/structure/fieldable-panels-panes/%fieldable_panels_panes_type',
'bundle argument' => 3,
'real path' => 'admin/structure/fieldable-panels-panes/map',
'access arguments' => array(
'administer fieldable panels panes',
),
),
);
$entity_info['fieldable_panels_pane']['bundles']['table'] = array(
'label' => t('Add table'),
'description' => t('Add table'),
'pane category' => t('Custom'),
'pane top level' => TRUE,
'pane icon' => drupal_get_path('module', 'panopoly_widgets') . '/images/icon_table.png',
'admin' => array(
'path' => 'admin/structure/fieldable-panels-panes/%fieldable_panels_panes_type',
'bundle argument' => 3,
'real path' => 'admin/structure/fieldable-panels-panes/table',
'access arguments' => array(
'administer fieldable panels panes',
),
),
);
$entity_info['fieldable_panels_pane']['bundles']['video'] = array(
'label' => t('Add video'),
'description' => t('Add video'),
'pane category' => t('Custom'),
'pane top level' => TRUE,
'pane icon' => drupal_get_path('module', 'panopoly_widgets') . '/images/icon_video.png',
'admin' => array(
'path' => 'admin/structure/fieldable-panels-panes/%fieldable_panels_panes_type',
'bundle argument' => 3,
'real path' => 'admin/structure/fieldable-panels-panes/video',
'access arguments' => array(
'administer fieldable panels panes',
),
),
);
$entity_info['fieldable_panels_pane']['bundles']['spotlight'] = array(
'label' => t('Add spotlight'),
'description' => t('Add spotlight'),
'pane category' => t('Custom'),
'pane top level' => TRUE,
'pane icon' => drupal_get_path('module', 'panopoly_widgets') . '/images/icon_spotlight.png',
'admin' => array(
'path' => 'admin/structure/fieldable-panels-panes/%fieldable_panels_panes_type',
'bundle argument' => 3,
'real path' => 'admin/structure/fieldable-panels-panes/spotlight',
'access arguments' => array(
'administer fieldable panels panes',
),
),
);
}
function panopoly_widgets_theme($existing, $type, $theme, $path) {
return array(
'panopoly_spotlight_wrapper' => array(
'render element' => 'element',
),
'panopoly_spotlight_view' => array(
'render element' => 'element',
),
);
}
function panopoly_widgets_field_display_fieldable_panels_pane_alter(&$display, $context) {
if ($context['field']['field_name'] == 'field_existing_content') {
$view_mode = $context['entity']->field_view_mode[LANGUAGE_NONE][0]['value'];
if (!empty($view_mode)) {
$display['settings']['view_mode'] = $view_mode;
}
}
}
function panopoly_widgets_file_default_displays_alter(&$default_displays) {
if (!empty($default_displays['video__preview__file_field_file_default'])) {
$default_displays['video__preview__file_field_file_default']->status = FALSE;
}
if (!empty($default_displays['video__default__media_vimeo_video'])) {
$default_displays['video__default__media_vimeo_video']->weight = 0;
$default_displays['video__default__media_vimeo_video']->settings['protocol_specify'] = FALSE;
}
if (!empty($default_displays['video__default__media_vimeo_image'])) {
$default_displays['video__default__media_vimeo_image']->settings['image_style'] = 'panopoly_image_video';
}
if (!empty($default_displays['video__teaser__media_vimeo_image'])) {
$default_displays['video__teaser__media_vimeo_image']->settings['image_style'] = 'panopoly_image_video';
}
if (!empty($default_displays['video__preview__media_vimeo_image'])) {
$default_displays['video__preview__media_vimeo_image']->settings['image_style'] = 'panopoly_image_thumbnail';
}
}
function panopoly_widgets_file_type_alter(&$types, $file) {
if ($file->filemime == 'video/youtube' || $file->filemime == 'video/vimeo') {
$types[] = 'video';
}
}
function panopoly_widgets_menu_block_tree_alter(&$tree, $config) {
if ($config['expanded'] && isset($config['expanded_max_depth']) && $config['expanded_max_depth'] > 0) {
_panopoly_widgets_menu_block_tree_expanded_max_depth_alter($tree, $config);
}
if (arg(0) == 'panels' && arg(1) == 'ajax') {
foreach ($tree as $key => $value) {
$tree[$key]['link']['in_active_trail'] = TRUE;
}
}
}
function _panopoly_widgets_menu_block_tree_expanded_max_depth_alter(&$tree, $config) {
foreach ($tree as $name => &$item) {
if (!$item['link']['in_active_trail'] && $item['link']['depth'] > $config['expanded_max_depth']) {
unset($tree[$name]);
}
else {
_panopoly_widgets_menu_block_tree_expanded_max_depth_alter($item['below'], $config);
}
}
}
function panopoly_widgets_fieldable_panels_pane_view($entity, $view_mode, $langcode) {
if ($entity->bundle == 'image') {
if (!empty($entity->field_basic_image_link[LANGUAGE_NONE][0]['url'])) {
$entity->content['field_basic_image_image'][0]['#path'] = array(
'path' => $entity->field_basic_image_link[LANGUAGE_NONE][0]['display_url'],
);
}
}
}
function panopoly_widgets_form_fieldable_panels_panes_fieldable_panels_pane_content_type_edit_form_alter(&$form, &$form_state) {
if (isset($form['widget_settings']['link'])) {
$element =& $form['widget_settings']['link'];
}
else {
$element =& $form['link'];
}
$element['path']['#linkit'] = array(
'enable' => TRUE,
'profile' => 'content_fields',
'button_text' => t('Search for existing content'),
);
}
function _panopoly_widgets_content_item_title_rewrite($nid, $title = NULL) {
static $saved_title = array();
$node = node_load($nid);
if (!is_null($title)) {
$saved_title[$nid] = $node->title;
$node->title = $title;
}
elseif (isset($saved_title[$nid])) {
$node->title = $saved_title[$nid];
}
}
function _panopoly_widgets_is_title_shown($node, $view_mode) {
if (!empty($node->panelizer) && (!empty($node->panelizer[$view_mode]) || !empty($node->panelizer['default']))) {
$panelizer_display = isset($node->panelizer[$view_mode]) ? $node->panelizer[$view_mode]->display : $node->panelizer['default']->display;
if (empty($panelizer_display->hide_title) && empty($panelizer_display->pane_title) && strpos($panelizer_display->title, '%node:title') !== FALSE) {
return TRUE;
}
else {
foreach ($panelizer_display->content as $pane) {
if ($pane->type == 'node_title' && $pane->subtype == 'node_title' || $pane->type == 'token' && $pane->subtype == 'node:title') {
return TRUE;
}
elseif ($pane->type == 'node_content' && $pane->subtype == 'node_content') {
$child_view_mode = $pane->configuration['build_mode'];
if ($child_view_mode == $view_mode) {
if ($child_view_mode != 'full') {
$child_view_mode = 'full';
}
else {
continue;
}
}
if (_panopoly_widgets_is_title_shown($node, $child_view_mode)) {
return TRUE;
}
}
}
return FALSE;
}
}
else {
return TRUE;
}
}
function panopoly_widgets_views_pre_view(&$view, &$display_id, &$args) {
if ($view->name == 'panopoly_widgets_general_content' && $display_id == 'piece_of_content') {
if (empty($view->exposed_input) || empty($view->exposed_input['nid']) && empty($view->exposed_input['title'])) {
$view->executed = TRUE;
}
}
}
function panopoly_widgets_views_default_views_alter(&$views) {
if (module_exists('locale') && array_key_exists('panopoly_widgets_general_content', $views)) {
$piece_of_content =& $views['panopoly_widgets_general_content']->display['piece_of_content'];
$piece_of_content->handler->display->display_options['filters']['language']['id'] = 'language';
$piece_of_content->handler->display->display_options['filters']['language']['table'] = 'node';
$piece_of_content->handler->display->display_options['filters']['language']['field'] = 'language';
$piece_of_content->handler->display->display_options['filters']['language']['value'] = array(
'***CURRENT_LANGUAGE***' => '***CURRENT_LANGUAGE***',
'und' => 'und',
);
}
}
function panopoly_widgets_views_post_execute(&$view) {
if ($view->name == 'panopoly_widgets_general_content' && $view->current_display == 'piece_of_content') {
$display =& $view->display[$view->current_display];
$row_plugin = $view->style_plugin->row_plugin;
if (is_a($row_plugin, 'entity_views_plugin_row_entity_view') && !empty($view->result[0])) {
$nid = $view->result[0]->nid;
$overridden_title = $display->handler->options['title'];
if (!empty($overridden_title)) {
_panopoly_widgets_content_item_title_rewrite($nid, $overridden_title);
$hide_pane_title = FALSE;
$node = node_load($nid);
if (_panopoly_widgets_is_title_shown($node, $row_plugin->options['view_mode'])) {
unset($display->handler->options['title']);
}
}
}
}
}
function panopoly_widgets_views_post_render(&$view) {
if ($view->name == 'panopoly_widgets_general_content' && $view->current_display == 'piece_of_content') {
$display = $view->display[$view->current_display];
if (is_a($view->style_plugin->row_plugin, 'entity_views_plugin_row_entity_view') && !empty($view->result[0])) {
_panopoly_widgets_content_item_title_rewrite($view->result[0]->nid);
}
}
}
function panopoly_widgets_form_views_exposed_form_alter(&$form, &$form_state) {
$view = $form_state['view'];
if ($view->name == 'panopoly_widgets_general_content' && $view->current_display == 'piece_of_content') {
$form['#after_build'][] = '_panopoly_widgets_piece_of_content_after_build';
}
}
function _panopoly_widgets_piece_of_content_after_build(&$form, &$form_state) {
$form['title']['#maxlength'] = NULL;
return $form;
}
function panopoly_widgets_form_views_content_views_panes_content_type_edit_form_alter(&$form, &$form_state) {
$view = $form_state['view'];
if ($view->name == 'panopoly_widgets_general_content' && $view->current_display == 'piece_of_content') {
$exposed =& $form['exposed'];
$exposed['filter-title']['title']['#maxlength'] = NULL;
$exposed['filter-title']['#required'] = TRUE;
$exposed['filter-title']['title']['#required'] = TRUE;
if (empty($exposed['filter-nid'])) {
return;
}
if (!empty($exposed['filter-nid']['nid']['#default_value'])) {
if ($node = node_load($exposed['filter-nid']['nid']['#default_value'])) {
$form_state['original_nid'] = $node->nid;
$form_state['original_title'] = $node->title;
$exposed['filter-title']['title']['#default_value'] = $node->title;
}
}
$exposed['filter-nid']['nid']['#default_value'] = '';
$exposed['filter-nid']['#access'] = FALSE;
array_unshift($form['#submit'], '_panopoly_widgets_content_item_form_submit');
}
}
function _panopoly_widgets_content_item_form_submit($form, &$form_state) {
$exposed =& $form_state['values']['exposed'];
if ($exposed['title'] != $form_state['original_title']) {
$view = views_get_view('panopoly_widgets_general_content');
$view
->set_display('piece_of_content');
$view
->set_exposed_input($exposed);
$view
->pre_execute();
$view
->execute($view->current_display);
$view
->post_execute();
if (count($view->result) > 0) {
$exposed['nid'] = $view->result[0]->nid;
$exposed['title'] = '';
}
}
else {
$exposed['nid'] = $form_state['original_nid'];
$exposed['title'] = '';
}
}