Problem/Motivation
When trying to use the widget in a render array (according to example in docs/examples/index.md and docs/api/overview.md), it gives a type error. If the '#components' key is removed then there is no error:
Gives Error
<pre>
$form['material_information'] = [
'#type' => 'fieldset',
'#title' => $this->t('Material Information'),
'#description' => $this->t('Please enter name as it appears in the publication.'),
'#description_display' => 'before',
[
'#type' => 'fieldset',
'#attributes' => [
'class' => [
'px-5',
],
],
[
'#type' => 'name',
'#title' => $this->t('Author/Artist/Editor/Translator'),
'#minimum_components' => [
'given' => 'given',
'family' => 'family',
],
'#components' => [
'given' => 'given',
'family' => 'family',
'title' => 'title',
'generational' => 'generational',
],
'#labels' => [
'title' => $this->t('Title'),
'given' => $this->t('Given/First Name'),
'family' => $this->t('Surname/Last Name'),
],
],
],
];
</pre>
No Error but ignores #labels and #minimum_components
<pre>
$form['material_information'] = [
'#type' => 'fieldset',
'#title' => $this->t('Material Information'),
'#description' => $this->t('Please enter name as it appears in the publication.'),
'#description_display' => 'before',
[
'#type' => 'fieldset',
'#attributes' => [
'class' => [
'px-5',
],
],
[
'#type' => 'name',
'#title' => $this->t('Author/Artist/Editor/Translator'),
'#minimum_components' => [
'given' => 'given',
'family' => 'family',
],
'#labels' => [
'title' => $this->t('Title'),
'given' => $this->t('Given/First Name'),
'family' => $this->t('Surname/Last Name'),
],
],
],
];
</pre>
TypeError: Drupal\Core\Render\Element::properties(): Argument #1 ($element) must be of type array, string given, called in /opt/drupal/web/modules/contrib/name/name.module on line 456 in Drupal\Core\Render\Element::properties() (line 38 of /opt/drupal/web/core/lib/Drupal/Core/Render/Element.php).
Backtrace:
#0 /opt/drupal/web/modules/contrib/name/name.module(456): Drupal\Core\Render\Element::properties('title')
#1 /opt/drupal/web/modules/contrib/name/name.module(412): name_element_render_component(Array, 'title', Array, false)
#2 [internal function]: name_element_expand(Array, Object(Drupal\Core\Form\FormState), Array)
#3 /opt/drupal/web/core/lib/Drupal/Core/Form/FormBuilder.php(1011): call_user_func_array('name_element_ex...', Array)
#4 /opt/drupal/web/core/lib/Drupal/Core/Form/FormBuilder.php(1074): Drupal\Core\Form\FormBuilder->doBuildForm('msul_faculty_au...', Array, Object(Drupal\Core\Form\FormState))
#5 /opt/drupal/web/core/lib/Drupal/Core/Form/FormBuilder.php(1074): Drupal\Core\Form\FormBuilder->doBuildForm('msul_faculty_au...', Array, Object(Drupal\Core\Form\FormState))
#6 /opt/drupal/web/core/lib/Drupal/Core/Form/FormBuilder.php(1074): Drupal\Core\Form\FormBuilder->doBuildForm('msul_faculty_au...', Array, Object(Drupal\Core\Form\FormState))
#7 /opt/drupal/web/core/lib/Drupal/Core/Form/FormBuilder.php(579): Drupal\Core\Form\FormBuilder->doBuildForm('msul_faculty_au...', Array, Object(Drupal\Core\Form\FormState))
#8 /opt/drupal/web/core/lib/Drupal/Core/Form/FormBuilder.php(326): Drupal\Core\Form\FormBuilder->processForm('msul_faculty_au...', Array, Object(Drupal\Core\Form\FormState))
#9 /opt/drupal/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\msul_faculty_authors\Form\FacultyAuthorInputForm), Object(Drupal\Core\Form\FormState))
#10 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#11 /opt/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#12 /opt/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(637): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#13 /opt/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#14 /opt/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#15 /opt/drupal/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#16 /opt/drupal/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#17 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /opt/drupal/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /opt/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(116): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /opt/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(90): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /opt/drupal/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /opt/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /opt/drupal/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#29 {main}
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
kwfinken commentedComment #3
kwfinken commentedComment #4
bluegeek9 commentedI will look into this. I think the documentation might be wrong.
Comment #5
bluegeek9 commentedThe components need to contain the element array, not the strings.
I will update the documentation.
Comment #8
bluegeek9 commentedhttps://project.pages.drupalcode.org/name/examples/widget/
Comment #9
bluegeek9 commented