Commit a9419bb9 authored by John C Fiala's avatar John C Fiala
Browse files

bug report #952656 by Dave_Reid:Moved hook_field_schema() to link.install,...

bug report #952656 by Dave_Reid:Moved hook_field_schema() to link.install, other small tweaks to remove old references.
parent 31ecd88c
......@@ -7,88 +7,35 @@
*/
/**
* Implementation of hook_install().
* Implements hook_field_schema().
*/
function link_install() {
drupal_load('module', 'content');
function link_field_schema($field) {
return array(
'columns' => array(
'url' => array(
'type' => 'varchar',
'length' => LINK_URL_MAX_LENGTH,
'not null' => FALSE,
'sortable' => TRUE
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'sortable' => TRUE
),
'attributes' => array(
'type' => 'text',
'size' => 'medium',
'not null' => FALSE
),
),
);
}
/**
* Implementation of hook_uninstall().
*/
function link_uninstall() {
drupal_load('module', 'content');
}
/**
* Implementation of hook_enable().
*/
function link_enable() {
drupal_load('module', 'content');
}
/**
* Implementation of hook_disable().
*/
function link_disable() {
drupal_load('module', 'content');
}
/**
* Removed link.module created tables, move data to content.module tables
*
* Even though most everyone will not be using this particular update, several
* folks have complained that their upgrades of link.module do not work because
* of this function being missing when schema expects it. - JCF
* And on further review, I'm removing the body, since some of those calls
* no longer exist in Drupal 6. Remember to upgrade from 4.7 to 5 first, and
* *then* from 5 to 6. kthx! -JCF
* Implements hook_update_last_removed().
*/
function link_update_1() {
$ret = array();
// GNDN
return $ret;
}
/**
* Ensure that content.module is updated before link module.
*/
function link_update_6000() {
if ($abort = content_check_update('link')) {
return $abort;
}
return array();
}
/**
* Change the database schema to allow NULL values.
*/
function link_update_6001() {
$ret = array();
// Build a list of fields that need updating.
$update_fields = array();
foreach (content_types_install() as $type_name => $fields) {
foreach ($fields as $field) {
if ($field['type'] == 'link') {
// We only process a given field once.
$update_fields[$field['field_name']] = $field;
}
}
}
// Update each field's storage to match the current definition.
foreach ($update_fields as $field) {
$db_info = content_database_info($field);
foreach ($db_info['columns'] as $column) {
db_change_field($ret, $db_info['table'], $column['column'], $column['column'], $column);
$ret[] = update_sql("UPDATE {". $db_info['table'] ."} SET ". $column['column'] ." = NULL WHERE ". $column['column'] ." = '' OR ". $column['column'] ." = 'N;'");
}
}
// Let CCK re-associate link fields with Link module and activate the fields.
content_associate_fields('link');
return $ret;
}
function link_update_last_removed() {
return 6001;
}
\ No newline at end of file
......@@ -41,33 +41,6 @@ function link_field_info() {
);
}
/**
* Implements hook_field_schema().
*/
function link_field_schema($field) {
return array(
'columns' => array(
'url' => array(
'type' => 'varchar',
'length' => LINK_URL_MAX_LENGTH,
'not null' => FALSE,
'sortable' => TRUE
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'sortable' => TRUE
),
'attributes' => array(
'type' => 'text',
'size' => 'medium',
'not null' => FALSE
),
),
);
}
/**
* Implements hook_field_settings_form().
*/
......@@ -181,132 +154,6 @@ function link_field_settings_form_validate($element, &$form_state, $complete_for
}
}
/**
* Implementation of hook_field_settings().
*
* I don't think this actually gets _used_ anymore.
*/
/*function link_field_settings($op, $field) {
switch ($op) {
case 'form':
$form = array(
'#theme' => 'link_field_settings',
);
$form['url'] = array(
'#type' => 'checkbox',
'#title' => t('Optional URL'),
'#default_value' => $field['url'],
'#return_value' => 'optional',
'#description' => t('If checked, the URL field is optional and submitting a title alone will be acceptable. If the URL is omitted, the title will be displayed as plain text.'),
);
$title_options = array(
'optional' => t('Optional Title'),
'required' => t('Required Title'),
'value' => t('Static Title: '),
'none' => t('No Title'),
);
$form['title'] = array(
'#type' => 'radios',
'#title' => t('Link Title'),
'#default_value' => isset($field['title']) ? $field['title'] : 'optional',
'#options' => $title_options,
'#description' => t('If the link title is optional or required, a field will be displayed to the end user. If the link title is static, the link will always use the same title. If <a href="http://drupal.org/project/token">token module</a> is installed, the static title value may use any other node field as its value. Static and token-based titles may include most inline XHTML tags such as <em>strong</em>, <em>em</em>, <em>img</em>, <em>span</em>, etc.'),
);
$form['title_value'] = array(
'#type' => 'textfield',
'#default_value' => $field['title_value'],
'#size' => '46',
);
// Add token module replacements
$form['tokens'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Placeholder tokens'),
'#description' => t("The following placeholder tokens can be used in both paths and titles. When used in a path or title, they will be replaced with the appropriate values."),
);
$form['tokens']['help'] = array(
'#value' => theme('token_help', 'node'),
);
$form['enable_tokens'] = array(
'#type' => 'checkbox',
'#title' => t('Allow user-entered tokens'),
'#default_value' => isset($field['enable_tokens']) ? $field['enable_tokens'] : 1,
'#description' => t('Checking will allow users to enter tokens in URLs and Titles on the node edit form. This does not affect the field settings on this page.'),
);
$form['display'] = array(
'#tree' => TRUE,
);
$form['display']['url_cutoff'] = array(
'#type' => 'textfield',
'#title' => t('URL Display Cutoff'),
'#default_value' => isset($field['display']['url_cutoff']) ? $field['display']['url_cutoff'] : '80',
'#description' => t('If the user does not include a title for this link, the URL will be used as the title. When should the link title be trimmed and finished with an elipsis (&hellip;)? Leave blank for no limit.'),
'#maxlength' => 3,
'#size' => 3,
);
$target_options = array(
LINK_TARGET_DEFAULT => t('Default (no target attribute)'),
LINK_TARGET_TOP => t('Open link in window root'),
LINK_TARGET_NEW_WINDOW => t('Open link in new window'),
LINK_TARGET_USER => t('Allow the user to choose'),
);
$form['attributes'] = array(
'#tree' => TRUE,
);
$form['attributes']['target'] = array(
'#type' => 'radios',
'#title' => t('Link Target'),
'#default_value' => empty($field['attributes']['target']) ? LINK_TARGET_DEFAULT : $field['attributes']['target'],
'#options' => $target_options,
);
$form['attributes']['rel'] = array(
'#type' => 'textfield',
'#title' => t('Rel Attribute'),
'#description' => t('When output, this link will have this rel attribute. The most common usage is <a href="http://en.wikipedia.org/wiki/Nofollow">rel=&quot;nofollow&quot;</a> which prevents some search engines from spidering entered links.'),
'#default_value' => empty($field['attributes']['rel']) ? '' : $field['attributes']['rel'],
'#field_prefix' => 'rel = "',
'#field_suffix' => '"',
'#size' => 20,
);
$form['attributes']['class'] = array(
'#type' => 'textfield',
'#title' => t('Additional CSS Class'),
'#description' => t('When output, this link will have have this class attribute. Multiple classes should be separated by spaces.'),
'#default_value' => empty($field['attributes']['class']) ? '' : $field['attributes']['class'],
);
return $form;
case 'validate':
if ($field['title'] == 'value' && empty($field['title_value'])) {
form_set_error('title_value', t('A default title must be provided if the title is a static value'));
}
break;
case 'save':
return array('attributes', 'display', 'url', 'title', 'title_value', 'enable_tokens');
case 'database columns':
return array(
'url' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE, 'sortable' => TRUE),
'title' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE, 'sortable' => TRUE),
'attributes' => array('type' => 'text', 'size' => 'medium', 'not null' => FALSE),
);
case 'views data':
module_load_include('inc', 'link', 'views/link.views');
return link_views_content_field_data($field);
}
}*/
/**
* Theme the settings form for the link field.
*/
......
......@@ -12,7 +12,7 @@ module_load_include('test', 'content', 'tests/content.crud');
class LinkAttributeCrudTest extends ContentCrudTestCase {
private $zebra;
public $permissions = array(
'access content',
'administer content types',
......@@ -20,7 +20,7 @@ class LinkAttributeCrudTest extends ContentCrudTestCase {
'administer filters',
'access comments',
'post comments',
'post comments without approval',
'skip comment approval',
'access administration pages',
);
......@@ -31,13 +31,13 @@ class LinkAttributeCrudTest extends ContentCrudTestCase {
'group' => t('Link'),
);
}
function setup() {
$this->zebra = 0;
parent::setup('link', 'views');
$this->loginWithPermissions($this->permissions);
}
function createLink($url, $title, $attributes = array()) {
return array(
'url' => $url,
......@@ -45,7 +45,7 @@ class LinkAttributeCrudTest extends ContentCrudTestCase {
'attributes' => $attributes,
);
}
private function outputScreenContents($description, $basename) {
// This is a hack to get a directory that won't be cleaned up by simpletest
$file_dir = file_directory_path().'/../simpletest_output_pages';
......@@ -56,8 +56,8 @@ class LinkAttributeCrudTest extends ContentCrudTestCase {
$rv = file_put_contents($output_path, $this->drupalGetContent());
$this->pass("$description: Contents of result page are ".l('here',$output_path));
}
private function assertLinkOnNode($field_name, $link_value, $message = '', $group = 'Other') {
private function assertLinkOnNode($field_name, $link_value, $message = '', $group = 'Other') {
$this->zebra++;
$zebra_string = ($this->zebra % 2 == 0) ? 'even' : 'odd';
$cssFieldLocator = 'field-'. str_replace('_', '-', $field_name);
......@@ -65,7 +65,7 @@ class LinkAttributeCrudTest extends ContentCrudTestCase {
$message,
$group);
}
/**
* A simple test that just creates a new node type, adds a link field to it, creates a new node of that type, and makes sure
* that the node is being displayed.
......@@ -94,14 +94,14 @@ class LinkAttributeCrudTest extends ContentCrudTestCase {
// Does this display on the node page?
$this->drupalGet('node/'. $this->nodes[0]->nid);
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com'));
// Does this display on the front page?
$this->drupalGet('<front>');
// reset the zebra!
$this->zebra = 0;
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com'));
}
/**
* This test sees that we can create a link field with a defined class, and make sure
* that class displays properly when the link is displayed.
......@@ -118,28 +118,28 @@ class LinkAttributeCrudTest extends ContentCrudTestCase {
'rel' => FALSE,
),
);
$field = $this->createField($field_settings, 0);
//$this->pass('<pre>'. print_r($field, TRUE) .'</pre>');
$field_db_info = content_database_info($field);
$this->acquireNodes(2);
$node = node_load($this->nodes[0]->nid);
$node->promote = 1; // We want this to show on front page for the teaser test.
$node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link');
node_save($node);
// Does this display on the node page?
$this->drupalGet('node/'. $this->nodes[0]->nid);
//$this->outputScreenContents('Link field with class', 'link_');
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'test-class'))));
// Does this display on the front page?
$this->drupalGet('<front>');
// reset the zebra!
$this->zebra = 0;
$this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'test-class'))));
}
}
\ No newline at end of file
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment