all contrib module security updates done

This commit is contained in:
2020-09-24 22:47:32 +02:00
parent 7d87153100
commit 0fbb9c4610
1612 changed files with 116663 additions and 32269 deletions
@@ -1,130 +0,0 @@
Title 7.x-1.x, xxxx-xx-xx
-------------------------
#1907078 by sylus: Fixed Undefined index: field_name() in
title_field_replacement_enabled().
#1961810 by peximo | fcortez: Fixed Wrap tag classes are not being inserted.
#1850866 by B-Prod: Fixed Undefined index 'format' in
title_field_text_with_summary_sync_set().
#1269076 by plach, das-peter, danielnolde | renat: Fixed Translated
title_field replaces node->title with translated value.
Title 7.x-1.0-alpha7, 2013-03-18
--------------------------------
#1919640 by peximo: Fixed Empty tag shown when the title field is displayed.
#1869438 by jsacksick: Fixed hook_field_attach_create_bundle() implementation
isn't correct.
#1280962 by mvc: Fixed Better description of field replacement dialogue.
#1900282: Fixed wrong files[] directive in the title_test module.
#1898618 by muka: Fixed Handle case when title property is not set (avoiding
error).
#1885356 by peximo: Fixed Empty HTML class in Linked and wrapped format.
#1865604 by GaëlG, plach: Fixed Title module overrides label callback (prevents
term label localization).
Title 7.x-1.0-alpha5, 2012-12-18
--------------------------------
#1869228 by plach: Updated system dependencies.
#1062814 by Andreas Radloff, jucallme | Scott J: Added Formatters.
#1849344 by peximo: Fixed Duplicate description element in taxonomy display
form.
#1482052 by peximo | joel rotelli, epieddy: Fixed Undefined property:
stdClass::$type dans title_tokens_alter().
#1761142 by joel_osc, plach | no2e: Fixed Replaced taxonomy description:
can't delete content (but editing works).
#1736476 by guillaumev: Made sure entity is accurate in title_entity_language().
#1748008 by vasike: Replaced fields should inherit the legacy field access.
#1808454 by plach: Fixed help and permissions for the admin settings.
#1835486 by plach: Fixed Automated tests are failing.
#1808454 by peximo: Overhauled the admin settings form.
#1773514 by peximo: Added Module's configuration page.
#1396450 by logaritmisk, plach | mgifford: Fixed Notice: Undefined index:
fieldable in title_entity_info_alter() (line 28 of title/title.module).
Title 7.x-1.0-alpha4, 2012-08-11
--------------------------------
#1708046 by plach | steinmb: Fixed Term description is overwritten.
#1709938 by Amitaibu: Prevented notice in title_field_attach_create_bundle().
#1541414 by peximo, plach | int_ua: Added No 'Link this field to the original
piece of content' option in Views UI for fields replaced with Title module.
#1704536 by RoySegall, Amitaibu, plach: Attach title field automatically when a
new entity bundle is created.
#1699092 by plach: Fixed Notices when submitting an empty taxonomy term
description.
#1665006 by mikey_p: Fixed Doesn't work when legacy title field is NULL.
#1613514 by steven.wichers, Amitaibu: Fixed Importing nodes in bulk fail to
create titles for all nodes after the first one.
#1644736 by plach: Fixed When initializing replaced fields all bundles are
processed.
#1631958 by plach | Goekmen: Fixed Undefined index: base path in
EntityTranslationDefaultHandler.
#1635006 by nikosnikos: Fixed Description summary desappear in taxonomy term.
#1528590 by torrance123, JonMcL: Fixed Reference to $form_state['values'] is
altering Views Bulk Operations modify action form submit.
#1445848 by danielnolde: Added Retain the original legacy field value to entity
in sync.
#1620986 by plach: Perform reverse synchronization more reliably.
#1519930 by plach, steinmb: Use the upcoming entity_language() function to
determine the entity language.
#1586002 by plach, Pisco: (follow-up) Fixed notices when changing node language.
Title 7.x-1.0-alpha3, 2012-06-05
--------------------------------
#1586002 by plach, Pisco | liquidcms: Fixed Entity language handling broken.
#1608980 by helior: Fixed Possible undefined indexes in
title_field_replacement_info().
#1362790 by colan, amateescu: Fixed Undefined property: stdClass::$title in
title_entity_update().
#1433060 by plach: Added Allow to use entity label fields in the entity content
area.
#1367118 by plach | BrightBold: Fixed Wrong menu item declaration for the field
replacement callback.
#1357220 by colan: Fixed Module should be listed in the Fields package.
#1323288 by das-peter: Fixed entitycache integration.
Title 7.x-1.0-alpha2, 2011-09-09
--------------------------------
#1229892 by plach | chrisdolby: Fixed Strict warning: Only variables should be
assigned by reference in title_field_attach_submit() - line 482 of
title.module.
#1219860 by plach, claudiu.cristea: Fixed Undefined index 'format'.
#1210670 by claudiu.cristea, das-peter | vasike: Fixed Entity translation errors
for Taxonomies entities.
Title 7.x-1.0-alpha1, 2011-09-07
--------------------------------
#1200320 by das-peter: Fixed Call field_attach_presave() before
field_attach_update() in field replacement batch.
#1155128 by das-peter | Dave Reid, plach: Enhanced support for tokens.
#1169394 by plach: Synchronized code after core fixes.
#1146724 by plach | das-peter, joostvdl: Fixed Replacing field values are not
initialized.
#1157438 by das-peter: Fixed Reset sync cache on entitycache reset.
#1116586 by plach | tte: Fixed Exception when a node's title is not converted
immediately.
#1138646 by plach | joostvdl, sun: Fixed Notice: Undefined index: label in
entity_get_info().
#1141674 by plach | manveru: Fixed Notices about missing $description.
#924968 by plach: Updated the change log.
#924968 by plach: Improved comments/PHP docs.
#924968 by plach: Introduced tests for field replacement UI.
#924968 by plach: Fixed field replacement checkbox broken.
#924968 by plach: Polished API as title_field_replacement_toggle does not belong
to title.admin.inc.
#924968 by plach: Fixed comments/PHP docs.
#924968 by plach: Disabled entity_label() support until #1096446 is fixed.
#924968 by plach: Introduced tests for field replacement workflow.
#924968 by plach: Moved administration code into title.admin.inc.
#924968 by plach: Added entity_label() support.
#924968 by plach: Fixed resave needed if field values altered before save.
#924968 by plach: Fixed entity forms to support nested subforms.
#924968 by plach: Added PHP docs.
#924968 by plach, das-peter, sun, fago, klonos: Introduced field replacement API
and UI.
by sun: Initial baseline of module files.
@@ -1,4 +1,3 @@
-- SUMMARY --
Title module allows entity titles/labels to be fully translatable.
@@ -8,30 +7,12 @@ For a full description of the module, visit the project page:
To submit bug reports and feature suggestions, or to track changes:
http://drupal.org/project/issues/title
-- REQUIREMENTS --
* @todo
-- INSTALLATION --
* Install as usual, see http://drupal.org/node/70151 for further information.
-- CONFIGURATION --
* @todo
-- USAGE --
* @todo
-- CONTACT --
Current maintainers:
* Francesco Placella (plach) - http://drupal.org/user/183211
* Daniel F. Kudwien (sun) - http://drupal.org/user/54136
@@ -0,0 +1,80 @@
<?php
/**
* Tests for legacy field replacement.
*/
class TitleAdminSettingsTestCase extends DrupalWebTestCase {
/**
*
*/
public static function getInfo() {
return array(
'name' => 'Admin settings',
'description' => 'Test the administration settings.',
'group' => 'Title',
);
}
/**
* Use the barebones "testing" installation profile.
*/
protected $profile = 'testing';
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
// Core.
$modules[] = 'field_test';
$modules[] = 'taxonomy';
// This module.
$modules[] = 'title';
$modules[] = 'title_test';
parent::setUp($modules);
/**
* Reset the permissions cache prior to calling drupalCreateUser.
* @see https://api.drupal.org/comment/28739#comment-28739
*/
$this->checkPermissions(array(), TRUE);
$admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer taxonomy', 'administer fields'));
$this->drupalLogin($admin_user);
}
/**
* Check for automated title_field attachment.
*/
public function testAutomatedFieldAttachment() {
$this->doTestAutomatedFieldAttachment(TRUE);
$this->doTestAutomatedFieldAttachment(FALSE);
}
/**
* Check that the fields are replaced or skipped depending on the given value.
*
* @param bool $enabled
* Whether replacement is enabled or not.
*/
public function doTestAutomatedFieldAttachment($enabled) {
$edit = array(
'title_taxonomy_term[auto_attach][name]' => $enabled,
'title_taxonomy_term[auto_attach][description]' => $enabled,
);
$this->drupalPost('admin/config/content/title', $edit, t('Save configuration'));
$edit = array(
'name' => $this->randomName(),
'machine_name' => drupal_strtolower($this->randomName()),
'description' => $this->randomString(16),
);
$this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
$entity_type = 'taxonomy_term';
$bundle = $edit['machine_name'];
field_info_cache_clear();
$this->assertTrue(title_field_replacement_enabled($entity_type, $bundle, 'name') == $enabled, 'Name field correctly processed.');
$this->assertTrue(title_field_replacement_enabled($entity_type, $bundle, 'description') == $enabled, 'Description field correctly processed.');
}
}
@@ -0,0 +1,177 @@
<?php
/**
* Tests for legacy field replacement.
*/
class TitleFieldReplacementTestCase extends DrupalWebTestCase {
/**
*
*/
public static function getInfo() {
return array(
'name' => 'Field replacement',
'description' => 'Test field replacement.',
'group' => 'Title',
'dependencies' => array('entity'),
);
}
/**
* Use the barebones "testing" installation profile.
*/
protected $profile = 'testing';
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
// Core.
$modules[] = 'comment';
$modules[] = 'field_test';
$modules[] = 'taxonomy';
// Other dependencies.
$modules[] = 'entity';
// This module.
$modules[] = 'title';
$modules[] = 'title_test';
parent::setUp($modules);
}
/**
* Test field replacement API and workflow.
*/
public function testFieldReplacementWorkflow() {
$info = entity_get_info('test_entity');
$label_key = $info['entity keys']['label'];
$field_name = $label_key . '_field';
// Enable field replacement for the test entity.
title_field_replacement_toggle('test_entity', 'test_bundle', $label_key);
$i = 0;
$entity = field_test_create_stub_entity(FALSE, FALSE);
while ($i++ <= 1) {
// The first time the entity gets created the second time gets updated.
title_test_entity_save($entity);
// Check that the replacing field value has been synchronized on save.
$query = db_select('test_entity', 'te');
$query->addJoin('INNER', 'field_data_' . $field_name, 'f', 'te.ftid = f.entity_id');
$record = $query
->fields('te')
->fields('f')
->condition('ftid', $entity->ftid)
->execute()
->fetch();
$phase = $entity->is_new ? 'insert' : 'update';
$this->assertIdentical($record->{$label_key}, $record->{$field_name . '_value'}, t('Field synchronization is correctly performed on %phase.', array('%phase' => $phase)));
unset($entity->is_new);
}
// Store a dummy value in the legacy field.
while (($label = $this->randomName()) == $entity->{$label_key}) {
}
db_update('test_entity')
->fields(array($label_key => $label))
->execute();
$record = db_select('test_entity', 'te')
->fields('te')
->condition('ftid', $entity->ftid)
->execute()
->fetch();
$this->assertNotIdentical($record->{$label_key}, $entity->{$label_key}, t('Entity label has been changed.'));
// Clear field cache so synchronization can be performed on field attach
// load.
cache_clear_all('*', 'cache_field');
drupal_static_reset();
// Check that the replacing field value is correctly synchronized on load
// and view.
$entity = title_test_entity_test_load($entity);
title_test_phase_check('after_load', $entity);
entity_view('test_entity', array($entity->ftid => $entity));
foreach (title_test_phase_store() as $phase => $value) {
$this->assertTrue($value, t('Field synchronization is correctly performed on %phase.', array('%phase' => $phase)));
}
// Change the value stored into the label field to check entity_label().
if (isset($info['label callback'])) {
$label = $this->randomName();
$entity->{$field_name}[LANGUAGE_NONE][0]['value'] = $label;
$this->assertIdentical(entity_label('test_entity', $entity), $label, t('entity_label() returns the expected value.'));
}
}
/**
* Test field replacement UI.
*/
public function testFieldReplacementUI() {
$permissions = array(
'access administration pages',
'view the administration theme',
'administer content types',
'administer taxonomy',
'administer comments',
'administer fields',
);
$admin_user = $this->drupalCreateUser($permissions);
$this->drupalLogin($admin_user);
foreach (entity_get_info() as $entity_type => $entity_info) {
if (!empty($entity_info['field replacement'])) {
foreach ($entity_info['bundles'] as $bundle => $bundle_info) {
if (isset($bundle_info['admin']['path'])) {
$admin_path = _field_ui_bundle_admin_path($entity_type, $bundle) . '/fields';
foreach ($entity_info['field replacement'] as $legacy_field => $info) {
$path = $admin_path . '/replace/' . $legacy_field;
$xpath = '//a[@href=:url and text()=:label]';
$args = array(':url' => url($path), ':label' => t('replace'));
$targs = array('%legacy_field' => $legacy_field, '%entity_type' => $entity_type, '%bundle' => $bundle);
$field_name = $info['field']['field_name'];
// Check that the current legacy field has a "replace" operation.
$this->drupalGet($admin_path);
$link = $this->xpath($xpath, $args);
$this->assertEqual(count($link), 1, t('Replace link found for the field %legacy_field of the bundle %bundle of the entity %entity_type.', $targs));
// Check that the legacy field has correctly been replaced through
// field replacement UI.
$this->drupalPost($path, array('enabled' => TRUE), t('Save settings'));
_field_info_collate_fields(TRUE);
$link = $this->xpath($xpath, $args);
$this->assertTrue(empty($link) && title_field_replacement_enabled($entity_type, $bundle, $legacy_field), t('%legacy_field successfully replaced for the bundle %bundle of the entity %entity_type.', $targs));
// Check that the enabled status cannot be changed unless the
// field instance is removed.
$this->drupalGet($path);
$this->assertFieldByXPath('//form//input[@name="enabled" and @checked="checked" and @disabled="disabled"]', NULL, t('Field replacement for %legacy_field cannot be disabled unless the replacing field instance is deleted.', array('%legacy_field' => $legacy_field)));
$this->drupalPost($path, array(), t('Save settings'));
_field_info_collate_fields(TRUE);
$this->assertTrue(title_field_replacement_enabled($entity_type, $bundle, $legacy_field), t('Submitting the form does not alter field replacement settings.'));
// Delete the field instance and check that the "replace"
// operation is available again.
$this->drupalPost($admin_path . '/' . $field_name . '/delete', array(), t('Delete'));
$link = $this->xpath($xpath, $args);
$this->assertEqual(count($link), 1, t('Replace link found for the field %legacy_field of the bundle %bundle of the entity %entity_type.', $targs));
// Check that field replacement can be enabled again.
$this->drupalGet($path);
$this->assertFieldByXPath('//form//input[@name="enabled" and not(@checked) and not(@disabled)]', NULL, t('Field replacement for %legacy_field cannot be disabled unless the replacing field instance is deleted.', array('%legacy_field' => $legacy_field)));
}
}
}
}
}
}
}
@@ -1,223 +1,52 @@
<?php
/**
* @file
* Tests for the Title module.
*/
/**
* Tests for legacy field replacement.
*/
class TitleFieldReplacementTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Field replacement',
'description' => 'Test field replacement.',
'group' => 'Title',
);
}
function setUp() {
parent::setUp('entity', 'field_test', 'title', 'title_test');
}
/**
* Test field replacement API and workflow.
*/
function testFieldReplacementWorkflow() {
$info = entity_get_info('test_entity');
$label_key = $info['entity keys']['label'];
$field_name = $label_key . '_field';
// Enable field replacement for the test entity.
title_field_replacement_toggle('test_entity', 'test_bundle', $label_key);
$i = 0;
$entity = field_test_create_stub_entity(FALSE, FALSE);
while ($i++ <= 1) {
// The first time the entity gets created the second time gets updated.
title_test_entity_save($entity);
// Check that the replacing field value has been synchronized on save.
$query = db_select('test_entity', 'te');
$query->addJoin('INNER', 'field_data_' . $field_name, 'f', 'te.ftid = f.entity_id');
$record = $query
->fields('te')
->fields('f')
->condition('ftid', $entity->ftid)
->execute()
->fetch();
$phase = $entity->is_new ? 'insert' : 'update';
$this->assertIdentical($record->{$label_key}, $record->{$field_name . '_value'}, t('Field synchronization is correctly performed on %phase.', array('%phase' => $phase)));
unset($entity->is_new);
}
// Store a dummy value in the legacy field.
while (($label = $this->randomName()) == $entity->{$label_key});
db_update('test_entity')
->fields(array($label_key => $label))
->execute();
$record = db_select('test_entity', 'te')
->fields('te')
->condition('ftid', $entity->ftid)
->execute()
->fetch();
$this->assertNotIdentical($record->{$label_key}, $entity->{$label_key}, t('Entity label has been changed.'));
// Clear field cache so synchronization can be performed on field attach
// load.
cache_clear_all('*', 'cache_field');
drupal_static_reset();
// Check that the replacing field value is correctly synchronized on load
// and view.
$entity = title_test_entity_test_load($entity);
title_test_phase_check('after_load', $entity);
$build = entity_view('test_entity', array($entity->ftid => $entity));
foreach (title_test_phase_store() as $phase => $value) {
$this->assertTrue($value, t('Field synchronization is correctly performed on %phase.', array('%phase' => $phase)));
}
// Change the value stored into the label field to check entity_label().
if (isset($info['label callback'])) {
$label = $this->randomName();
$entity->{$field_name}[LANGUAGE_NONE][0]['value'] = $label;
$this->assertIdentical(entity_label('test_entity', $entity), $label, t('entity_label() returns the expected value.'));
}
}
/**
* Test field replacement UI.
*/
function testFieldReplacementUI() {
$admin_user = $this->drupalCreateUser(array('access administration pages', 'view the administration theme', 'administer content types', 'administer taxonomy', 'administer comments'));
$this->drupalLogin($admin_user);
foreach (entity_get_info() as $entity_type => $entity_info) {
if (!empty($entity_info['field replacement'])) {
foreach ($entity_info['bundles'] as $bundle => $bundle_info) {
if (isset($bundle_info['admin']['path'])) {
$admin_path = _field_ui_bundle_admin_path($entity_type, $bundle) . '/fields';
foreach ($entity_info['field replacement'] as $legacy_field => $info) {
$path = $admin_path . '/replace/' . $legacy_field;
$xpath = '//a[@href=:url and text()=:label]';
$args = array(':url' => url($path), ':label' => t('replace'));
$targs = array('%legacy_field' => $legacy_field, '%entity_type' => $entity_type, '%bundle' => $bundle);
$field_name = $info['field']['field_name'];
// Check that the current legacy field has a "replace" operation.
$this->drupalGet($admin_path);
$link = $this->xpath($xpath, $args);
$this->assertEqual(count($link), 1, t('Replace link found for the field %legacy_field of the bundle %bundle of the entity %entity_type.', $targs));
// Check that the legacy field has correctly been replaced through
// field replacement UI.
$this->drupalPost($path, array('enabled' => TRUE), t('Save settings'));
_field_info_collate_fields(TRUE);
$link = $this->xpath($xpath, $args);
$this->assertTrue(empty($link) && title_field_replacement_enabled($entity_type, $bundle, $legacy_field), t('%legacy_field successfully replaced for the bundle %bundle of the entity %entity_type.', $targs));
// Check that the enabled status cannot be changed unless the
// field instance is removed.
$this->drupalGet($path);
$this->assertFieldByXPath('//form//input[@name="enabled" and @checked="checked" and @disabled="disabled"]', NULL, t('Field replacement for %legacy_field cannot be disabled unless the replacing field instance is deleted.', array('%legacy_field' => $legacy_field)));
$this->drupalPost($path, array(), t('Save settings'));
_field_info_collate_fields(TRUE);
$this->assertTrue(title_field_replacement_enabled($entity_type, $bundle, $legacy_field), t('Submitting the form does not alter field replacement settings.'));
// Delete the field instance and check that the "replace"
// operation is available again.
$this->drupalPost($admin_path . '/' . $field_name . '/delete', array(), t('Delete'));
$link = $this->xpath($xpath, $args);
$this->assertEqual(count($link), 1, t('Replace link found for the field %legacy_field of the bundle %bundle of the entity %entity_type.', $targs));
// Check that field replacement can be enabled again.
$this->drupalGet($path);
$this->assertFieldByXPath('//form//input[@name="enabled" and not(@checked) and not(@disabled)]', NULL, t('Field replacement for %legacy_field cannot be disabled unless the replacing field instance is deleted.', array('%legacy_field' => $legacy_field)));
}
}
}
}
}
}
}
/**
* Tests for legacy field replacement.
*/
class TitleAdminSettingsTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Admin settings',
'description' => 'Test the administration settings.',
'group' => 'Title',
);
}
function setUp() {
parent::setUp('field_test', 'title', 'title_test');
$admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer taxonomy'));
$this->drupalLogin($admin_user);
}
/**
* Check for automated title_field attachment.
*/
function testAutomatedFieldAttachement() {
$this->assertAutomatedFieldAttachement(TRUE);
$this->assertAutomatedFieldAttachement(FALSE);
}
/**
* Check that the fields are replaced or skipped depdening on the given value.
*/
function assertAutomatedFieldAttachement($enabled) {
$edit = array(
'title_taxonomy_term[auto_attach][name]' => $enabled,
'title_taxonomy_term[auto_attach][description]' => $enabled,
);
$this->drupalPost('admin/config/content/title', $edit, t('Save configuration'));
$edit = array(
'name' => $this->randomName(),
'machine_name' => drupal_strtolower($this->randomName()),
'description' => $this->randomString(16),
);
$this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
$entity_type = 'taxonomy_term';
$bundle = $edit['machine_name'];
field_info_cache_clear();
$this->assertTrue(title_field_replacement_enabled($entity_type, $bundle, 'name') == $enabled, 'Name field correctly processed.');
$this->assertTrue(title_field_replacement_enabled($entity_type, $bundle, 'description') == $enabled, 'Description field correctly processed.');
}
}
/**
* Tests for legacy field replacement.
*/
class TitleTranslationTestCase extends DrupalWebTestCase {
/**
*
*/
public static function getInfo() {
return array(
'name' => 'Replaced fields translation',
'description' => 'Test replaced field translation.',
'group' => 'Title',
'dependencies' => array('entity_translation'),
);
}
protected function setUp() {
parent::setUp('locale', 'entity_translation', 'title', 'field_test', 'title_test');
/**
* Use the barebones "testing" installation profile.
*/
protected $profile = 'testing';
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
// Core.
$modules[] = 'field_test';
$modules[] = 'locale';
$modules[] = 'taxonomy';
// Other dependencies.
$modules[] = 'entity_translation';
// This module.
$modules[] = 'title';
$modules[] = 'title_test';
parent::setUp($modules);
// Create a power user.
$admin_user = $this->drupalCreateUser(array('administer modules', 'view the administration theme', 'administer languages', 'administer taxonomy', 'administer entity translation', 'translate any entity'));
$permissions = array(
'administer modules',
'view the administration theme',
'administer languages',
'administer taxonomy',
'administer entity translation',
'translate any entity',
);
$admin_user = $this->drupalCreateUser($permissions);
$this->drupalLogin($admin_user);
// Enable a translation language.
@@ -242,6 +71,7 @@ class TitleTranslationTestCase extends DrupalWebTestCase {
$edit = array(
'name' => $this->randomString(),
'machine_name' => $name,
'entity_translation_taxonomy' => 1,
);
$this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
$this->vocabulary = taxonomy_vocabulary_machine_name_load($name);
@@ -406,6 +236,14 @@ class TitleTranslationTestCase extends DrupalWebTestCase {
/**
* Loads a term using the given language as active language.
*
* @param int $tid
* The term identifier.
* @param string|null $langcode
* (optional) The active language to be set. Defaults to none.
*
* @return object|bool
* A term object.
*/
protected function termLoad($tid, $langcode = NULL) {
drupal_static_reset();
@@ -425,7 +263,10 @@ class TitleTranslationTestCase extends DrupalWebTestCase {
}
/**
* Checks that the field values and optionally the legacy ones match the given values.
* Checks the field values.
*
* Checks that the field values and optionally the legacy ones match the given
* values.
*/
protected function checkFieldValues($term, $values, $langcode, $legacy_match = TRUE) {
foreach ($values as $name => $value) {
@@ -438,7 +279,7 @@ class TitleTranslationTestCase extends DrupalWebTestCase {
}
/**
* Checks that the legacy field values stored in the database match the given values.
* Checks that the legacy field values in the database match the given values.
*/
protected function checkLegacyValues($term, $values) {
$record = db_query('SELECT * FROM {taxonomy_term_data} t WHERE t.tid = :tid', array(':tid' => $term->tid))->fetchAssoc();
@@ -4,12 +4,12 @@ core = 7.x
package = Testing
hidden = TRUE
dependencies[] = title
dependencies[] = taxonomy
dependencies[] = entity
dependencies[] = entity_translation
; Information added by drupal.org packaging script on 2013-04-15
version = "7.x-1.0-alpha7+4-dev"
; Information added by Drupal.org packaging script on 2020-09-21
version = "7.x-1.0-beta3+3-dev"
core = "7.x"
project = "title"
datestamp = "1366034249"
datestamp = "1600677287"
@@ -4,4 +4,3 @@
* @file
* Installation functionality for Title Test module.
*/
@@ -86,7 +86,11 @@ function title_test_phase_check($phase, $entity) {
$info = entity_get_info('test_entity');
$label_key = $info['entity keys']['label'];
$field_name = $label_key . '_field';
$value = $entity->{$label_key} == $entity->{$field_name}[LANGUAGE_NONE][0]['value'];
$langcode = LANGUAGE_NONE;
if (isset($entity->type)) {
$langcode = entity_language($entity->type, $entity);
}
$value = $entity->{$label_key} == $entity->{$field_name}[$langcode][0]['value'];
title_test_phase_store($phase, $value);
return $value;
}
@@ -14,20 +14,16 @@ function title_form_field_ui_overview(&$form, &$form_state) {
if (!empty($entity_info['field replacement'])) {
$field_replacement_info = $entity_info['field replacement'];
$admin_path = _field_ui_bundle_admin_path($form['#entity_type'], $form['#bundle']);
$form['fields']['#header'][6]['colspan'] += 1;
foreach (element_children($form['fields']) as $field_name) {
if (isset($field_replacement_info[$field_name])) {
$form['fields'][$field_name]['field_replacement'] = array(
$form['fields'][$field_name]['delete'] = array(
'#type' => 'link',
'#title' => t('replace'),
'#href' => $admin_path . '/fields/replace/' . $field_name,
'#options' => array('attributes' => array('title' => t('Replace %field with a customizable field instance that can be translated.', array('%field' => $field_name)))),
);
}
else {
$form['fields'][$field_name]['field_replacement'] = array();
}
}
}
}
@@ -60,7 +56,7 @@ function title_field_replacement_form($form, $form_state, $entity_type, $bundle,
}
/**
* Process field replacement form subissions.
* Process field replacement form submissions.
*/
function title_field_replacement_form_submit($form, &$form_state) {
if ($form_state['values']['enabled'] != $form['enabled']['#default_value']) {
@@ -76,13 +72,31 @@ function title_field_replacement_form_submit($form, &$form_state) {
}
/**
* Form settings for automated title_field attachement.
* Form settings for automated title_field attachment.
*/
function title_admin_settings_form() {
$form['tabs'] = array(
'#type' => 'vertical_tabs',
);
$form['settings']['title_general'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
'#group' => 'tabs',
'#title' => t('General'),
);
$general = variable_get('title_general', array('maxlength' => 255));
$form['settings']['title_general']['maxlength'] = array(
'#type' => 'textfield',
'#title' => t('Default maximum field length'),
'#description' => t('The default maximum length for the title field. This setting will have no effect once a title field for a specific entity type has been created, because the maximum field length is a global field setting and the databases tables will already have been created with a specific length.'),
'#element_validate' => array('element_validate_integer_positive'),
'#default_value' => $general['maxlength'],
);
foreach (entity_get_info() as $entity_type => $info) {
if (empty($info['field replacement'])) {
continue;
@@ -94,7 +108,7 @@ function title_admin_settings_form() {
'#collapsed' => TRUE,
'#tree' => TRUE,
'#group' => 'tabs',
'#title' => $info['label'],
'#title' => check_plain($info['label']),
);
$options = array();
@@ -4,4 +4,3 @@
* @file
* API documentation for Title module.
*/
@@ -2,6 +2,8 @@
/**
* @file
* Provide field replacement information.
*
* Provide field replacement information for core entities and type specific
* callbacks.
*/
@@ -12,10 +14,15 @@
function title_entity_info() {
$info = array();
$general_settings = variable_get('title_general', array('maxlength' => 255));
$field = array(
'type' => 'text',
'cardinality' => 1,
'translatable' => TRUE,
'settings' => array(
'max_length' => $general_settings['maxlength'],
),
);
$instance = array(
@@ -41,6 +48,9 @@ function title_entity_info() {
'label' => t('Title'),
'description' => '',
) + $instance,
'additional keys' => array(
'format' => 'format',
),
),
),
'efq bundle conditions' => TRUE,
@@ -112,7 +122,7 @@ function title_field_term_description_submit($entity_type, $entity, $legacy_fiel
// If the keys are not defined an empty value has been submitted, hence we
// need to update the term description accordingly.
else {
$values['description'][$key] = ($key == 'value') ? '' : filter_default_format();
$values['description'][$key] = ($key == 'value') ? '' : filter_default_format();
}
}
}
@@ -122,12 +132,31 @@ function title_field_term_description_submit($entity_type, $entity, $legacy_fiel
*/
function title_field_text_sync_get($entity_type, $entity, $legacy_field, $info, $langcode) {
$value = NULL;
$format = 'plain_text';
$info += array(
'additional keys' => array(
'format' => 'format',
),
);
$format_key = $info['additional keys']['format'];
$field_name = $info['field']['field_name'];
// Return values only if there is any available to process for the current
// language.
if (!empty($entity->{$field_name}[$langcode]) && is_array($entity->{$field_name}[$langcode])) {
$items = $entity->{$field_name}[$langcode];
$value = !empty($items[0]['value']) ? $items[0]['value'] : NULL;
$item = $entity->{$field_name}[$langcode][0] + array(
'value' => NULL,
'format' => NULL,
);
$value = $item['value'];
$format = $item['format'];
}
return array($legacy_field => $value);
return array(
$legacy_field => $value,
$format_key => $format,
);
}
/**
@@ -143,15 +172,26 @@ function title_field_text_sync_set($entity_type, $entity, $legacy_field, $info,
function title_field_text_with_summary_sync_get($entity_type, $entity, $legacy_field, $info, $langcode) {
$value = NULL;
$format = NULL;
$info += array(
'additional keys' => array(
'format' => 'format',
),
);
$format_key = $info['additional keys']['format'];
$field_name = $info['field']['field_name'];
// Return values only if there is any available to process for the current
// language.
if (!empty($entity->{$field_name}[$langcode]) && is_array($entity->{$field_name}[$langcode])) {
$items = $entity->{$field_name}[$langcode];
$value = !empty($items[0]['value']) ? $items[0]['value'] : NULL;
$format = $entity->{$field_name}[$langcode][0]['format'];
$item = $entity->{$field_name}[$langcode][0] + array(
'value' => NULL,
'format' => NULL,
);
$value = $item['value'];
$format = $item['format'];
}
return array(
$legacy_field => $value,
$format_key => $format,
@@ -0,0 +1,116 @@
<?php
/**
* @file
* Drush commands for Title module.
*/
/**
* Implements hook_drush_help().
*/
function title_drush_help($section) {
switch ($section) {
case 'drush:upgrade-title-fields':
return dt('Upgrade title fields to use title module, so that titles can be localized.');
}
}
/**
* Implements hook_drush_command().
*/
function title_drush_command() {
$items['upgrade-title-fields'] = array(
'description' => 'Upgrade title fields to use title module, so that titles can be localized.',
'drupal dependencies' => array('title', 'entity_translation'),
);
$items['upgrade-title-field'] = array(
'description' => 'Upgrade a title field on a legacy field. DO NOT call this command directly, it does not do any checking.',
'hidden' => TRUE,
'arguments' => array(
'entity_type' => 'The type of entity, be it a node, user, term, etc.',
'bundle' => 'The entity bundle.',
'legacy_field' => 'The machine name of the legace field.',
),
);
return $items;
}
/**
* Command callback for upgrade-title-fields.
*/
function drush_title_upgrade_title_fields() {
$entity_type = 'node';
$entity_info = entity_get_info($entity_type);
if (empty($entity_info['field replacement'])) {
drush_log(t('There are no available title fields to upgrade.'), 'error');
return FALSE;
}
$field_replacement_info = $entity_info['field replacement'];
$upgraded = $failed = $skipped = 0;
foreach (title_content_types() as $bundle) {
$dt_args['@bundle'] = $bundle;
$field_instances = field_info_instances($entity_type, $bundle);
$extra_fields = field_info_extra_fields($entity_type, $bundle, 'form');
$possible_fields = array_merge($field_instances, $extra_fields);
if ($info = array_intersect_key($field_replacement_info, $possible_fields)) {
foreach (array_keys($info) as $legacy_field) {
$dt_args['@legacy_field'] = $legacy_field;
if (drush_invoke_process('@self', 'upgrade-title-field', array($entity_type, $bundle, $legacy_field))) {
$upgraded++;
}
else {
$failed++;
}
}
}
else {
$skipped++;
drush_log(dt('Title fields have already been upgraded on content type @bundle.', $dt_args), 'ok');
}
}
$messages = array();
if ($upgraded) {
$dt_args['@upgraded'] = $upgraded;
$messages[] = 'Upgraded @upgraded title field(s).';
}
if ($skipped) {
$dt_args['@skipped'] = $skipped;
$messages[] = 'Skipped @skipped title field(s).';
}
if ($failed) {
$dt_args['@failed'] = $failed;
$messages[] = '@failed failed.';
}
$message = empty($messages) ? 'No fields upgraded.' : implode(' ', $messages);
drush_log(dt($message, $dt_args), 'completed');
if ($failed) {
return FALSE;
}
}
/**
* Command callback for upgrade-title-field.
*/
function drush_title_upgrade_title_field($entity_type, $bundle, $legacy_field) {
$dt_args['@entity_type'] = $entity_type;
$dt_args['@bundle'] = $bundle;
$dt_args['@field'] = $legacy_field;
if (!title_field_replacement_toggle($entity_type, $bundle, $legacy_field)) {
drush_log(dt("Failed to upgrade title field '@field' on content type @bundle.", $dt_args), 'warning');
return FALSE;
}
title_field_replacement_batch_set($entity_type, $bundle, $legacy_field);
drush_backend_batch_process();
if (drush_get_error()) {
drush_log(dt("Failed upgrading title field '@field' on bundle '@bundle'. Your database is likely messed up now. Sorry about that.", $dt_args), 'error');
return FALSE;
}
drush_log(dt("Upgraded title field '@field' on content type @bundle.", $dt_args), 'success');
return TRUE;
}
@@ -5,7 +5,6 @@
* Implement a title field formater.
*/
/**
* Implements hook_field_formatter_info().
*/
@@ -14,7 +13,13 @@ function title_field_formatter_info() {
'title_linked' => array(
'label' => t('Linked and wrapped'),
'field types' => array('text'),
'settings' => array('title_style' => '', 'title_link' => '', 'title_class' => ''),
'settings' => array(
'title_style' => '',
'title_link' => '',
'title_class' => '',
'enable_trim' => FALSE,
'trim_length' => 50,
),
),
);
}
@@ -45,7 +50,8 @@ function title_field_formatter_settings_form($field, $instance, $view_mode, $for
);
$link_types = array(
'content' => t('Content'),
'content' => t('Content (relative url)'),
'content_absolute' => t('Content (absolute url)'),
);
$element['title_link'] = array(
'#title' => t('Link title to'),
@@ -55,6 +61,25 @@ function title_field_formatter_settings_form($field, $instance, $view_mode, $for
'#options' => $link_types,
);
$element['enable_trim'] = array(
'#type' => 'checkbox',
'#title' => t('Enable trimming?'),
'#default_value' => $settings['enable_trim'],
);
$element['trim_length'] = array(
'#title' => t('Trim length'),
'#type' => 'textfield',
'#size' => 10,
'#default_value' => $settings['trim_length'],
'#element_validate' => array('element_validate_integer_positive'),
'#states' => array(
'visible' => array(
':input[name*="enable_trim"]' => array('checked' => TRUE),
),
),
);
$element['title_class'] = array(
'#title' => t('Tag classes'),
'#type' => 'textfield',
@@ -78,6 +103,7 @@ function title_field_formatter_settings_summary($field, $instance, $view_mode) {
$link_types = array(
'content' => t('Linked to content'),
'content_absolute' => t('Linked to content(absolute url)'),
);
// Display this setting only if field is linked.
if (isset($link_types[$settings['title_link']])) {
@@ -89,6 +115,11 @@ function title_field_formatter_settings_summary($field, $instance, $view_mode) {
$summary[] = t('Wrap tag classes: @classes', array('@classes' => $settings['title_class']));
}
// Display this setting only if trim is enabled.
if (!empty($settings['enable_trim'])) {
$summary[] = t('Trim length: @length', array('@length' => $settings['trim_length']));
}
return implode('<br />', $summary);
}
@@ -97,51 +128,98 @@ function title_field_formatter_settings_summary($field, $instance, $view_mode) {
*/
function title_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$settings = $display['settings'];
$output = isset($items[0]) ? $items[0]['safe_value'] : '';
if (!empty($output) && $settings['title_link'] == 'content') {
$uri = entity_uri($entity_type, $entity);
$output = l($output, $uri['path'], array('html' => TRUE));
$output = '';
if (isset($items[0]['safe_value'])) {
$output = $items[0]['safe_value'];
}
elseif (isset($items[0]['value'])) {
$output = _text_sanitize($instance, $langcode, $items[0], 'value');
}
$element = array();
$wrap_tag = empty($settings['title_style']) ? '_none' : $settings['title_style'];
if ($wrap_tag != '_none') {
$variables = array(
'element' => array(
'#tag' => $wrap_tag,
'#value' => $output,
),
);
if (!empty($settings['title_class'])) {
$variables['element']['#attributes'] = array('class' => $settings['title_class']);
if (!empty($output)) {
if (in_array($settings['title_link'], array(
'content',
'content_absolute',
))) {
$uri = entity_uri($entity_type, $entity);
// If trimmed is enabled.
if (!empty($settings['enable_trim'])) {
$trimmed_output = text_summary($output, $instance['settings']['text_processing'] ? $items[0]['format'] : NULL, $display['settings']['trim_length']);
// If we performed trimmed, add ellipsis in the end.
if (drupal_strlen($output) != drupal_strlen($trimmed_output)) {
$output = $trimmed_output . '&hellip;';
}
}
$options = array(
'html' => TRUE,
'absolute' => $settings['title_link'] === 'content_absolute',
);
if (!empty($uri['options'])) {
$options = array_merge($options, $uri['options']);
}
$output = l($output, $uri['path'], $options);
}
$output = theme('html_tag', $variables);
$wrap_tag = empty($settings['title_style']) ? '_none' : $settings['title_style'];
if ($wrap_tag != '_none') {
$variables = array(
'element' => array(
'#tag' => $wrap_tag,
'#value' => $output,
),
);
if (!empty($settings['title_class'])) {
$variables['element']['#attributes'] = array('class' => $settings['title_class']);
}
$output = theme('html_tag', $variables);
}
$element = array(
array(
'#markup' => $output,
),
);
}
$element = array(
array(
'#markup' => $output,
),
);
return $element;
}
/**
* Validate that a space-separated list of values are lowercase and appropriate for use as HTML classes.
* Validate the list of values.
*
* Validate that a space-separated list of values are lowercase and appropriate
* for use as HTML classes.
*
* @see title_field_formatter_settings_form()
*/
function _title_validate_class($element, &$form_state) {
static $validated_class = array();
$value = drupal_array_get_nested_value($form_state['values'], $element['#parents']);
$classes = explode(' ', $value);
foreach ($classes as $class) {
if ($class != drupal_html_class($class)) {
form_error($element, t('Wrapper classes contain illegal characters; classes should be lowercase and may contain letters, numbers, and dashes.'));
if (!isset($validated_class[$class])) {
// Using drupal_clean_css_identifier() directly to allow a double
// underscore in addition to core defaults.
// @see: https://www.drupal.org/node/2009584.
$validated_class[$class] = drupal_clean_css_identifier(
drupal_strtolower($class),
array(
' ' => '-',
'__' => '__',
'_' => '-',
'/' => '-',
'[' => '-',
']' => '',
)
);
}
if ($class !== $validated_class[$class]) {
form_error($element, t('Wrapper classes contain illegal characters; classes should be lowercase and may contain letters, numbers, dashes and double underscores.'));
return;
}
}
@@ -5,13 +5,17 @@ package = Fields
configure = admin/config/content/title
dependencies[] = system (>7.14)
files[] = title.module
files[] = views/views_handler_title_field.inc
files[] = tests/title.test
; Information added by drupal.org packaging script on 2013-04-15
version = "7.x-1.0-alpha7+4-dev"
; Tests.
test_dependencies[] = entity
test_dependencies[] = entity_translation
files[] = tests/TitleAdminSettingsTestCase.test
files[] = tests/TitleFieldReplacementTestCase.test
files[] = tests/TitleTranslationTestCase.test
; Information added by Drupal.org packaging script on 2020-09-21
version = "7.x-1.0-beta3+3-dev"
core = "7.x"
project = "title"
datestamp = "1366034249"
datestamp = "1600677287"
@@ -25,8 +25,28 @@ function title_install() {
}
/**
* Implements hook_update_N.
*
* Implements hook_disable().
*/
function title_disable() {
foreach (field_read_fields() as $field) {
if ($field['type'] !== 'taxonomy_term_reference') {
continue;
}
if ($field['settings']['options_list_callback'] !== 'title_taxonomy_allowed_values') {
continue;
}
$field['settings']['options_list_callback'] = '';
field_update_field($field);
}
}
/**
* Implements hook_update_N().
*/
/**
* Make sure Title has a very high weight to be able to perform reverse
* synchronization reliably.
*/
@@ -35,8 +55,6 @@ function title_update_7001() {
}
/**
* Implements hook_update_N.
*
* Update title_auto_attach variables to the new format.
*/
function title_update_7002() {
@@ -37,6 +37,15 @@ function title_module_implements_alter(&$implementations, $hook) {
$implementations['title'] = $group;
break;
// The following hook implementations should be executed after
// entity_translation.
case 'entity_load':
if (isset($implementations['entity_translation'])) {
$length = array_search('entity_translation', array_keys($implementations)) + 1;
$implementations = array_merge(array_slice($implementations, 0, $length, TRUE), array('title' => $group), array_slice($implementations, $length, count($implementations) - 1, TRUE));
}
break;
// Normally Title needs to act as first module to perform synchronization.
default:
$implementations = array('title' => $group) + $implementations;
@@ -88,7 +97,7 @@ function title_entity_info_alter(&$info) {
* @param $entity_type
* The name of the entity type.
* @param $legacy_field
* (Otional) The legacy field name to be replaced.
* (Optional) The legacy field name to be replaced.
*/
function title_field_replacement_info($entity_type, $legacy_field = NULL) {
$info = entity_get_info($entity_type);
@@ -99,23 +108,12 @@ function title_field_replacement_info($entity_type, $legacy_field = NULL) {
if (isset($legacy_field)) {
return isset($info['field replacement'][$legacy_field]) ? $info['field replacement'][$legacy_field] : FALSE;
}
else {
return $info['field replacement'];
}
return $info['field replacement'];
}
/**
* Return an entity label value.
*
* @param $entity
* The entity whose label has to be displayed.
* @param $type
* The name of the entity type.
* @param $langcode
* (Optional) The language the entity label has to be displayed in.
*
* @return
* The entity label as a string value.
* Implements callback_entity_info_label().
*/
function title_entity_label($entity, $type, $langcode = NULL) {
$entity_info = entity_get_info($type);
@@ -127,15 +125,15 @@ function title_entity_label($entity, $type, $langcode = NULL) {
if (title_field_replacement_enabled($type, $bundle, $legacy_field)) {
$langcode = field_language($type, $entity, $info['field']['field_name'], $langcode);
$values = $info['callbacks']['sync_get']($type, $entity, $legacy_field, $info, $langcode);
return $values[$legacy_field];
return isset($values[$legacy_field]) ? $values[$legacy_field] : $entity->{$legacy_field};
}
if (isset($entity_info['label fallback']['title']) && function_exists($entity_info['label fallback']['title'])) {
$label = $entity_info['label fallback']['title']($entity, $type, $langcode);
return isset($label) ? $label : $entity->{$legacy_field};
}
// Otherwise if we have a fallback defined we use the original label callback.
elseif (isset($entity_info['label fallback']['title']) && function_exists($entity_info['label fallback']['title'])) {
return $entity_info['label fallback']['title']($entity, $type, $langcode);
}
else {
return (property_exists($entity, $legacy_field)) ? $entity->{$legacy_field} : NULL;
}
return property_exists($entity, $legacy_field) ? $entity->{$legacy_field} : NULL;
}
/**
@@ -185,7 +183,7 @@ function title_field_attach_update($entity_type, $entity) {
// Reset the field_attach_presave static cache so that subsequent saves work
// correctly.
$sync = &drupal_static('title_field_attach_presave', array());
list($id, , ) = entity_extract_ids($entity_type, $entity);
list($id, ,) = entity_extract_ids($entity_type, $entity);
unset($sync[$entity_type][$id]);
// Immediately after saving the entity we need to ensure that the legacy field
@@ -203,7 +201,10 @@ function title_field_attach_update($entity_type, $entity) {
* @see title_entity_load()
*/
function title_field_attach_load($entity_type, $entities, $age, $options) {
// @todo: Do we need to handle revisions here?
// Allow values to re-sync when field_attach_load_revision() is called.
if ($age == FIELD_LOAD_REVISION) {
title_entity_sync_static_reset($entity_type, array_keys($entities));
}
title_entity_load($entities, $entity_type);
}
@@ -215,9 +216,23 @@ function title_field_attach_load($entity_type, $entities, $age, $options) {
* replaced fields.
*/
function title_entity_load($entities, $type) {
// Load entity translations otherwise field language will not be computed
// correctly.
if (module_exists('entity_translation')) {
module_invoke('entity_translation', 'entity_load', $entities, $type);
}
foreach ($entities as &$entity) {
// Synchronize values from the regular field unless we are intializing it.
title_entity_sync($type, $entity, NULL, !empty($GLOBALS['title_field_replacement_init']));
// When the node is not being edited, the language must be set to current
// entity language if set, otherwise NULL.
$language = NULL;
if ((preg_match('/node\/\d+\/edit/', current_path()) == 0)
&& (preg_match('/node\/\d+$/', current_path()) == 0)) {
if (!empty($entity->language)) {
$language = $entity->language;
}
}
title_entity_sync($type, $entity, $language, !empty($GLOBALS['title_field_replacement_init']));
}
}
@@ -234,20 +249,10 @@ function title_entitycache_load($entities, $type) {
/**
* Implements hook_entitycache_reset().
*
* If the entity cache is reseted the field sync has to be done again.
* When the entity cache is reset the field sync has to be done again.
*/
function title_entitycache_reset($ids, $entity_type) {
$sync = &drupal_static('title_entity_sync', array());
if (!empty($ids)) {
// Clear specific ids.
foreach ($ids as $id) {
unset($sync[$entity_type][$id]);
}
}
elseif (!empty($sync[$entity_type])) {
// Reset cache for an entity_type.
$sync[$entity_type] = array();
}
title_entity_sync_static_reset($entity_type, $ids);
}
/**
@@ -316,10 +321,9 @@ function title_field_replacement_toggle($entity_type, $bundle, $legacy_field) {
field_create_instance($info['instance']);
return TRUE;
}
else {
field_delete_instance($instance);
return FALSE;
}
field_delete_instance($instance);
return FALSE;
}
/**
@@ -450,6 +454,26 @@ function title_entity_sync($entity_type, &$entity, $langcode = NULL, $set = FALS
}
}
/**
* Reset the list of entities whose fields have already been synchronized.
*
* @param $entity_type
* The name of the entity type.
* @param $entity_ids
* Either an array of entity IDs to reset or NULL to reset all.
*/
function title_entity_sync_static_reset($entity_type, $entity_ids = NULL) {
$sync = &drupal_static('title_entity_sync', array());
if (is_array($entity_ids)) {
foreach ($entity_ids as $id) {
unset($sync[$entity_type][$id]);
}
}
else {
unset($sync[$entity_type]);
}
}
/**
* Synchronize a single legacy field with its regular field value.
*
@@ -459,8 +483,6 @@ function title_entity_sync($entity_type, &$entity, $langcode = NULL, $set = FALS
* The entity to work with.
* @param $legacy_field
* The name of the legacy field to be replaced.
* @param $field_name
* The regular field to use as source value.
* @param $info
* Field replacement information for the given entity.
* @param $langcode
@@ -474,8 +496,16 @@ function title_field_sync_get($entity_type, $entity, $legacy_field, $info, $lang
$langcode = field_language($entity_type, $entity, $info['field']['field_name'], $langcode);
$values = $info['callbacks']['sync_get']($entity_type, $entity, $legacy_field, $info, $langcode);
foreach ($values as $name => $value) {
$entity->{$name} = $value;
if ($value !== NULL) {
$entity->{$name} = $value;
}
}
// Save the actual language used to LEGACY_FIELD_NAME_language.
$entity->{$legacy_field . '_language'} = $langcode;
// Ensure we do not pollute field language static cache.
$cache = &drupal_static('field_language');
list($id, ,) = entity_extract_ids($entity_type, $entity);
unset($cache[$entity_type][$id]);
}
}
@@ -488,8 +518,6 @@ function title_field_sync_get($entity_type, $entity, $legacy_field, $info, $lang
* The entity to work with.
* @param $legacy_field
* The name of the legacy field to be replaced.
* @param $field_name
* The regular field to use as source value.
* @param $info
* Field replacement information for the given entity.
* @param $langcode
@@ -564,13 +592,20 @@ function title_field_attach_form($entity_type, $entity, &$form, &$form_state, $l
$fr_info = title_field_replacement_info($entity_type);
if (!empty($fr_info)) {
foreach ($fr_info as $legacy_field => $info) {
foreach ($fr_info as $legacy_field => $info) {
if (isset($form[$legacy_field]) && title_field_replacement_enabled($entity_type, $bundle, $legacy_field)) {
// Inherit the access from the title widget, so that other modules
// restricting access to it keep working.
if (isset($form[$legacy_field]['#access'])) {
$replaced = isset($form[$legacy_field]['#field_replacement']) ?
$form[$legacy_field]['#field_replacement'] : FALSE;
if (!$replaced && isset($form[$legacy_field]['#access'])) {
$form[$info['field']['field_name']]['#access'] = $form[$legacy_field]['#access'];
}
// Add class from legacy field so behaviors can still be applied on
// title widget.
$form[$info['field']['field_name']]['#attributes']['class'] = array('form-item-' . $legacy_field);
// Restrict access to the legacy field form element and mark it as
// replaced.
$form[$legacy_field]['#access'] = FALSE;
@@ -600,8 +635,6 @@ function title_field_attach_submit($entity_type, $entity, $form, &$form_state) {
foreach ($fr_info as $legacy_field => $info) {
if (!empty($form[$legacy_field]['#field_replacement'])) {
$field_name = $info['field']['field_name'];
// Give a chance to operate on submitted values either.
if (!empty($info['callbacks']['submit'])) {
$info['callbacks']['submit']($entity_type, $entity, $legacy_field, $info, $langcode, $values);
@@ -617,7 +650,7 @@ function title_field_attach_submit($entity_type, $entity, $form, &$form_state) {
}
/**
* Implements of hook_menu().
* Implements hook_menu().
*/
function title_menu() {
$items = array();
@@ -643,7 +676,7 @@ function title_menu() {
);
$path = "$path/fields/replace/%";
$field_arg = count(explode('/', $path)) - 1;
$field_arg = substr_count($path, '/');
$items[$path] = array(
'load arguments' => array(),
'title' => 'Replace fields',
@@ -674,7 +707,7 @@ function title_menu() {
function title_help($path, $arg) {
switch ($path) {
case 'admin/config/content/title':
return '<p>' . t('The settings below allow to configure the <em>default</em> settings to be used when creating new replacing fields. It is even possibile to configure them so that the selected fields are created automatically when a new bundle is created.') . '</p>';
return '<p>' . t('The settings below allow to configure the <em>default</em> settings to be used when creating new replacing fields. It is even possible to configure them so that the selected fields are created automatically when a new bundle is created.') . '</p>';
}
}
@@ -689,7 +722,7 @@ function title_field_extra_fields_alter(&$info) {
foreach ($entity_info[$entity_type]['field replacement'] as $field_name => $field_replacement_info) {
if (title_field_replacement_enabled($entity_type, $bundle_name, $field_name)) {
// Remove the replaced legacy field.
unset($info[$entity_type][$bundle_name]['form'][$field_name], $info[$entity_type][$bundle_name]['display'][$field_name]);
unset($info[$entity_type][$bundle_name]['form'][$field_name], $info[$entity_type][$bundle_name]['display'][$field_name]);
}
}
}
@@ -725,7 +758,7 @@ function title_tokens_alter(array &$replacements, array $context) {
$fr_info = title_field_replacement_info($entity_type);
if ($fr_info && !empty($context['data'][$context['type']])) {
$entity = $context['data'][$context['type']];
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
$options = $context['options'];
// Since Title tokens are mostly used in storage contexts we default to
@@ -736,16 +769,17 @@ function title_tokens_alter(array &$replacements, array $context) {
if ($fr_info) {
foreach ($fr_info as $legacy_field => $info) {
if (title_field_replacement_enabled($entity_type, $bundle, $legacy_field)) {
if (isset($context['tokens'][$legacy_field])) {
$langcode = field_language($entity_type, $entity, $info['field']['field_name'], $langcode);
$values = $info['callbacks']['sync_get']($entity_type, $entity, $legacy_field, $info, $langcode);
$item = $values[$legacy_field];
if (!empty($item)) {
if (is_array($item)) {
$item = reset($item);
}
$replacements[$context['tokens'][$legacy_field]] = $item;
if (isset($context['tokens'][$legacy_field])
&& title_field_replacement_enabled($entity_type, $bundle, $legacy_field)) {
$langcode = field_language($entity_type, $entity, $info['field']['field_name'], $langcode);
$item = $info['callbacks']['sync_get']($entity_type, $entity, $legacy_field, $info, $langcode);
if (!empty($item)) {
list($value, $format) = array_values($item);
if (empty($format)) {
$replacements[$context['tokens'][$legacy_field]] = check_plain($value);
}
else {
$replacements[$context['tokens'][$legacy_field]] = check_markup($value, $format, $langcode);
}
}
}
@@ -810,13 +844,13 @@ function title_field_replacement_is_label($entity_type, $field_name) {
/**
* Returns the legacy field replaced by the given field name.
*
* @param $entity_type
* @param $entity_type
* The name of the entity type.
* @param $field_name
* The replacing field name.
*
* @return
* The replaced legacy field name or FALSE if none available.
* @return
* The replaced legacy field name or FALSE if none available.
*/
function title_field_replacement_get_legacy_field($entity_type, $field_name) {
$result = FALSE;
@@ -842,7 +876,7 @@ function title_field_replacement_get_legacy_field($entity_type, $field_name) {
* @param $bundle
* The name of the bundle the instance is attached to.
*
* @return
* @return
* The field instance replacing the label or FALSE if none available.
*/
function title_field_replacement_get_label_field($entity_type, $bundle) {
@@ -939,3 +973,65 @@ function title_field_attach_create_bundle($entity_type, $bundle) {
}
}
}
/**
* Implements hook_field_info_alter().
*/
function title_field_info_alter(&$info) {
$supported_types = array('taxonomy_term_reference' => TRUE);
foreach ($info as $field_type => &$field_type_info) {
if (isset($supported_types[$field_type])) {
if (!isset($field_type_info['settings'])) {
$field_type_info['settings'] = array();
}
$field_type_info['settings'] += array('options_list_callback' => 'title_taxonomy_allowed_values');
}
}
}
/**
* Return taxonomy term values for taxonomy reference fields.
*/
function title_taxonomy_allowed_values($field) {
// Since we call taxonomy_get_tree() with $load_entities = TRUE, there is a
// chance that this will trigger theme functions. For this case, we need to
// ensure that we are not in the process of theme registry rebuilding.
$theme_registry_cache = drupal_static('theme_get_registry');
/* @see theme_get_registry() */
$theme_registry_is_rebuilding = is_array($theme_registry_cache) &&
empty($theme_registry_cache);
$bundle = !empty($field['settings']['allowed_values'][0]['vocabulary']) ?
$field['settings']['allowed_values'][0]['vocabulary'] : NULL;
if ($bundle && ($label = title_field_replacement_get_label_field('taxonomy_term', $bundle)) && !$theme_registry_is_rebuilding) {
$options = array();
foreach ($field['settings']['allowed_values'] as $tree) {
$vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary']);
if ($vocabulary && ($terms = taxonomy_get_tree($vocabulary->vid, $tree['parent'], NULL, TRUE))) {
foreach ($terms as $term) {
$options[$term->tid] = str_repeat('-', $term->depth) . entity_label('taxonomy_term', $term);
}
}
}
return $options;
}
return taxonomy_allowed_values($field);
}
/**
* Implements hook_ctools_context_converter_alter().
*/
function title_ctools_context_converter_alter($context, $converter, &$value, &$converter_options) {
// This is a temporary fix for https://www.drupal.org/node/2505311.
// It fixes a language issue for the pane title containing entity
// related keywords.
if (isset($context->type[0]) && 0 === strpos($context->type[0], 'entity:') && empty($converter_options['language'])) {
$plugin = ctools_get_context($context->plugin);
if ($function = ctools_plugin_get_function($plugin, 'convert')) {
// Provide "language" option for converter and perform the conversion
// again.
$converter_options['language'] = $GLOBALS[LANGUAGE_TYPE_CONTENT];
$value = $function($context, $converter, $converter_options);
}
}
}
@@ -1,18 +1,28 @@
<?php
/**
* Implements hook_views_data_alter().
*
* Replace field default handler (views_handler_field_field).
* @file
* Provides support for the Views module.
*/
function title_field_views_data_alter(&$data) {
/**
* Implements hook_field_views_data_alter().
*/
function title_field_views_data_alter(&$result, $field, $module) {
// Replace field default handler (views_handler_field_field).
foreach (entity_get_info() as $entity_type => $entity_info) {
$replacements = title_field_replacement_info($entity_type);
if ($replacements) {
foreach ($replacements as $replacement) {
$entity_info += array(
'field replacement' => array(),
);
foreach ($entity_info['field replacement'] as $replacement) {
if (isset($replacement['field']['field_name'])) {
$field = field_info_field($replacement['field']['field_name']);
$table = _field_sql_storage_tablename($field);
if (isset($data[$table][$field['field_name']])) {
$data[$table][$field['field_name']]['field']['handler'] = 'views_handler_title_field';
if (!empty($field)) {
$table = _field_sql_storage_tablename($field);
if (isset($result[$table][$field['field_name']])) {
$result[$table][$field['field_name']]['field']['handler'] = 'views_handler_title_field';
}
}
}
}
@@ -1,4 +1,5 @@
<?php
/**
* Field handler to present field title with link to the entity.
*
@@ -6,7 +7,10 @@
*/
class views_handler_title_field extends views_handler_field_field {
function option_definition() {
/**
*
*/
public function option_definition() {
$options = parent::option_definition();
$options['link_to_entity'] = array('default' => isset($this->definition['link_to_entity default']) ? $this->definition['link_to_entity default'] : FALSE);
return $options;
@@ -16,7 +20,7 @@ class views_handler_title_field extends views_handler_field_field {
/**
* Provide link to entity option.
*/
function options_form(&$form, &$form_state) {
public function options_form(&$form, &$form_state) {
$form['link_to_entity'] = array(
'#title' => t('Link this field to the original entity'),
'#description' => t("Enable to override this field's links."),
@@ -27,24 +31,31 @@ class views_handler_title_field extends views_handler_field_field {
parent::options_form($form, $form_state);
}
function advanced_render($values) {
/**
*
*/
public function advanced_render($values) {
$this->original_values = $values;
return parent::advanced_render($values);
}
function render_item($count, $item) {
/**
*
*/
public function render_item($count, $item) {
if (!empty($this->options['link_to_entity'])) {
$values = $this->original_values;
$entity_type = $this->definition['entity_tables'][$this->base_table];
$entity_info = entity_get_info($entity_type);
$key = $entity_info['entity keys']['id'];
$key = $this->field_alias;
if (!empty($values->_field_data[$key]['entity'])) {
$entity = $values->_field_data[$key]['entity'];
$uri = entity_uri($entity_type, $entity);
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = $uri['path'];
$this->options['alter']['options'] = !empty($uri['options']) ? $uri['options'] : array();
}
}
return parent::render_item($count, $item);
}
}