Commit ca836396 authored by catch's avatar catch
Browse files

Issue #3134554 by Matroskeen, larowlan, paulocs, aluzzardi, phenaproxima,...

Issue #3134554 by Matroskeen, larowlan, paulocs, aluzzardi, phenaproxima, mark_fullmer, vierlex, hchonov, grathbone: Media fields with Media Library form widget trigger PHP 'Notice: Undefined index'
parent a6ee84df
......@@ -174,13 +174,14 @@ protected function getAllowedMediaTypeIdsSorted() {
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = [];
$media_type_ids = $this->getAllowedMediaTypeIdsSorted();
if (count($media_type_ids) <= 1) {
return $form;
return $elements;
}
$form['media_types'] = [
$elements['media_types'] = [
'#type' => 'table',
'#header' => [
$this->t('Tab order'),
......@@ -200,7 +201,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
$weight = 0;
foreach ($media_types as $media_type_id => $media_type) {
$label = $media_type->label();
$form['media_types'][$media_type_id] = [
$elements['media_types'][$media_type_id] = [
'label' => ['#markup' => $label],
'weight' => [
'#type' => 'weight',
......@@ -215,7 +216,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
$weight++;
}
return $form;
return $elements;
}
/**
......
......@@ -163,6 +163,12 @@ public function testWidget() {
$expected_link_titles = ['Show Type Three media (selected)', 'Show Type One media', 'Show Type Two media', 'Show Type Four media'];
$this->assertSame($link_titles, $expected_link_titles);
$this->drupalGet('admin/structure/types/manage/basic_page/form-display');
// Ensure that the widget settings form is not displayed when only
// one media type is allowed.
$assert_session->pageTextContains('Single media type');
$assert_session->buttonNotExists('field_single_media_type_settings_edit');
$assert_session->buttonExists('field_twin_media_settings_edit')->press();
$this->assertElementExistsAfterWait('css', '#field-twin-media .tabledrag-toggle-weight')->press();
$assert_session->fieldExists('fields[field_twin_media][settings_edit_form][settings][media_types][type_one][weight]')->selectOption(0);
......
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