Commit 340d11b0 authored by alexpott's avatar alexpott

Issue #2571593 by dawehner, lauriii, Berdir: Fatal error: Cannot use object of...

Issue #2571593 by dawehner, lauriii, Berdir: Fatal error: Cannot use object of type Drupal\Core\GeneratedLink as array in Tableselect.php on line 220
parent 7a25f513
......@@ -10,6 +10,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Component\Utility\Html as HtmlUtility;
use Drupal\Core\StringTranslation\TranslatableString;
/**
* Provides a form element for a table with radios or checkboxes in left column.
......@@ -217,10 +218,12 @@ public static function processTableselect(&$element, FormStateInterface $form_st
if (!isset($element[$key])) {
if ($element['#multiple']) {
$title = '';
if (!empty($element['#options'][$key]['title']['data']['#title'])) {
$title = t('Update @title', array(
'@title' => $element['#options'][$key]['title']['data']['#title'],
));
if (isset($element['#options'][$key]['title']) && is_array($element['#options'][$key]['title'])) {
if (!empty($element['#options'][$key]['title']['data']['#title'])) {
$title = new TranslatableString('Update @title', array(
'@title' => $element['#options'][$key]['title']['data']['#title'],
));
}
}
$element[$key] = array(
'#type' => 'checkbox',
......
<?php
/**
* @file
* Contains \Drupal\Tests\Core\Render\Element\TableSelectTest.
*/
namespace Drupal\Tests\Core\Render\Element;
use Drupal\Core\Form\FormState;
use Drupal\Core\Link;
use Drupal\Core\Render\Element\Tableselect;
use Drupal\Core\StringTranslation\TranslatableString;
use Drupal\Core\StringTranslation\TranslationWrapper;
use Drupal\Core\Url;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\Core\Render\Element\Tableselect
* @group Render
*/
class TableSelectTest extends UnitTestCase {
/**
* @covers ::processTableselect
*/
public function testProcessTableselectWithLinkTitle() {
$element = [];
$form_state = new FormState();
$complete_form = [];
$element_object = new Tableselect([], 'table_select', []);
$info = $element_object->getInfo();
$element += $info;
$element['#value'] = 0;
$element['#options'][] = [
'title' => new Link('my-text', Url::fromRoute('<front>'))
];
$element['#attributes'] = [];
Tableselect::processTableselect($element, $form_state, $complete_form);
$this->assertEquals('', $element[0]['#title']);
}
/**
* @covers ::processTableselect
*/
public function testProcessTableselectWithStringTitle() {
$element = [];
$form_state = new FormState();
$complete_form = [];
$element_object = new Tableselect([], 'table_select', []);
$info = $element_object->getInfo();
$element += $info;
$element['#value'] = 0;
$element['#options'][] = [
'title' => ['data' => ['#title' => 'Static title']],
];
$element['#attributes'] = [];
Tableselect::processTableselect($element, $form_state, $complete_form);
$this->assertEquals(new TranslatableString('Update @title', ['@title' => 'Static title']), $element[0]['#title']);
}
}
Markdown is supported
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