I am trying to get a value of my custom attribute linkedin_value to populate a form I have added to customer account edit page but I cannot get to it. As soon as I call $block->anything or $this->getParentBlock()->anything, the page sort of crashes. $this->getParentBlock() returns false. Could you please explain why and how can I get my value.

It is working 80% because the field appears where I want it to appear, and I can even type in a value and it gets saved.

The idea was to do something like this. I can do it from the edit.phtml but I don't want to override the whole template, just add one field.

<?php $linkedinAttribute = $block->getCustomer()->getCustomAttribute('linkedin_profile');
    $linkedinDefaultValue = '';
    if ($linkedinAttribute) {
        $linkedinDefaultValue = $linkedinAttribute->getValue();

This is the stock layout customer_account_edit.xml:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="customer_account"/>
    <referenceBlock name="head.components">
        <block class="Magento\Framework\View\Element\Js\Components" name="customer_account_edit_head_components" template="Magento_Customer::js/components.phtml"/>
    <referenceBlock name="page.main.title">
        <action method="setPageTitle">
            <argument translate="true" name="title" xsi:type="string">Edit Account Information</argument>
    <referenceContainer name="content">
        <block class="Magento\Customer\Block\Form\Edit" name="customer_edit" template="Magento_Customer::form/edit.phtml" cacheable="false">
            <container name="form.additional.info" as="form_additional_info"/>

My addition to the layout inside my module:

        <referenceContainer name="form.additional.info">
            <block class="Magento\Framework\View\Element\Template" name="additional_info_edit_customer_linkedin_profile" template="MyVendor_MyModule::customer/editadditionalinfocustomer.phtml"/>

My template:

<fieldset class="fieldset edit linkedin_profile" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>">
<legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Additional Information') ?></span></legend>
<div class="field regulation">
    <label for="linkedin_profile" class="label"><span><?php /* @escapeNotVerified */ echo __('Linkedin Profile') ?></span></label>
    <div class="control">
        <!--            {required:true, 'maxlength':250, 'validate-url':true}-->
        <input type="text" name="linkedin_profile" data-role="edit-linkedin-profile" id="linkedin_profile" title="<?php /* @escapeNotVerified */ echo __('Linkedin Profile') ?>" class="input-text"/>

My template is getting called inside the edit.phtml like so:

<?= $block->getChildHtml('form_additional_info') ?>

I reckon this should be easy, because the value is getting saved, so it must be connected to the correct underlying block and logic. My guess is that this snag has something to do with how getChildHtml() works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.