contentanalysisexample.module in Content Analysis 7
Same filename and directory in other branches
An example content analyzer using the Content Analysis API
File
APIEXAMPLE/contentanalysisexample.moduleView source
<?php
/**
* @file
* An example content analyzer using the Content Analysis API
*/
/**
* Implements hook_contentanalysis_analyzers().
* register contentanalysisexample with contentanalysis analyzers registry
*/
function contentanalysisexample_contentanalysis_analyzers() {
$analyzers['contentanalysisexample'] = array(
'title' => t('Example'),
'module' => 'contentanalysisexample',
'callback' => 'contentanalysisexample_analyzer',
'form elements callback' => 'contentanalysisexample_analyzer_form_elements',
'node form submit callback' => 'contentanalysisexample_node_form_submit',
'weight' => -5,
);
return $analyzers;
}
/**
* Implements hook_analyzer_form_elements() via custom define callback
*
* hook to add any analyzier specific form elements to the content analyzer form.
* callback is defined in hook_contentanalysis_analyzers ['form elements callback']
*
* @param $form_state
* Array defined by form_api
* @param $analysis
* Array analysis formatted array defined in conentanalysis
* @param $node
* Node object
* @return mixed
*/
function contentanalysisexample_analyzer_form_elements($form_state, $analysis = '', $node = 0) {
drupal_add_css(drupal_get_path('module', 'contentanalysisexample') . '/contentanalysisexample.css');
drupal_add_js(drupal_get_path('module', 'contentanalysisexample') . '/contentanalysisexample.js');
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Whats your name'),
);
return $form;
}
/**
* Implements hook_node_form_submit() via custom define callback
* @param $form
* Array defined by form_api
* @param $form_state
* Array defined by form_api
*/
function contentanalysisexample_node_form_submit($form, &$form_state) {
drupal_set_message(t('You actually submitted that rubbish? Come on, you can do better. If you don\'t like this relentless taunting, disable the Content Analysis Example module'));
}
/**
* Implements hook_analyzer() via custom define callback
*
* Performs the analysis.
* callback is defined in hook_contentanalysis_analyzers ['callback']
*
* @param unknown_type $context
* Array context format defined by contentanalysis.module
* @param unknown_type $analysis
* Array analysis format defined by contentanalysis.module
* @param unknown_type $params
* Array customer defined paramters
* @return \unknown_type
*/
function contentanalysisexample_analyzer($context, $analysis, $params) {
$subject = t('World');
$name = $context['inputs']['analyzer_options']['contentanalysisexample']['name'];
if ($name) {
$subject = $name;
$analysis['messages'][] = contentanalysis_format_message(t('Good job, you submitted your name.'), 'complete');
$analysis['#status'] = 'complete';
}
else {
$analysis['messages'][] = contentanalysis_format_message(t('Your name was not entered in the options field. Please enter it to make this warning go away.'), 'warning');
$analysis['#status'] = 'warning';
}
$analysis['content'][] = contentanalysis_format_content('<strong>' . t('Hello ' . $subject) . '</strong>', -5);
return $analysis;
}
Functions
Name![]() |
Description |
---|---|
contentanalysisexample_analyzer | Implements hook_analyzer() via custom define callback |
contentanalysisexample_analyzer_form_elements | Implements hook_analyzer_form_elements() via custom define callback |
contentanalysisexample_contentanalysis_analyzers | Implements hook_contentanalysis_analyzers(). register contentanalysisexample with contentanalysis analyzers registry |
contentanalysisexample_node_form_submit | Implements hook_node_form_submit() via custom define callback |