Magento 2 XML – Fix Customer_index_index XML Data Error

magento2xml

I have created custom customer attribute by using new module and run the InstallData.php –

namespace mynamespace\modulename\Setup;

use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetup;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface {

/**
 * Customer setup factory
 *
 * @var \Magento\Customer\Setup\CustomerSetupFactory
 */
private $customerSetupFactory;

public function __construct(CustomerSetupFactory $customerSetupFactory) {
    $this->customerSetupFactory = $customerSetupFactory;
}

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
    $setup->startSetup();
    /** @var CustomerSetup $customerSetup */
    $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

    $customerSetup->addAttribute(Customer::ENTITY, 'service_agreement', [
        'type' => 'int',
        'input' => 'select',
        'position' => 25,
        'label' => 'Service Agreement',
        'required' => false,
        'sort_order' => 120,
        'source' => 'Magento\Config\Model\Config\Source\Yesno',
        'visible' => true,
        'system' => false ]
        //'is_used_in_grid' => true,
        //'is_visible_in_grid' => true,
        //'is_filterable_in_grid' => true,
        //'is_searchable_in_grid' => true]
    );

    // add attribute to form
    /** @var  $attribute */
    $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'service_agreement');
    $attribute->setData('used_in_forms', ['adminhtml_customer', 'customer_account_create']);
    $attribute->save();

    $setup->endSetup();
}

}

using magento setup:upgrade it installed and attribute created but when I going to "All customer" section from admin section its give me 500 error. As I check in log file its showing below error –

main.INFO: Cache file with merged layout: LAYOUT_adminhtml_STORE1_518574bb8b0fd6fa628f8c37dcd7903e2 and handles default, customer_index_index: Please correct the XML data and try again.  [] []
main.INFO: Cache file with merged layout: LAYOUT_adminhtml_STORE1_5cf9ab1b1723bedc1dcd665a812b00335 and handles admin-1column: Please correct the XML data and try again.  [] []
main.CRITICAL: Broken reference: the 'header' tries to reorder itself towards 'global.notices', but their parents are different: 'page.wrapper' and 'notices.wrapper' respectively. [] []
main.CRITICAL: Broken reference: the 'page.breadcrumbs' tries to reorder itself towards 'notifications', but their parents are different: 'page.wrapper' and 'notices.wrapper' respectively. [] []
main.CRITICAL: Broken reference: the 'global.search' tries to reorder itself towards 'notification.messages', but their parents are different: 'header.inner.right' and 'header' respectively. [] []

I am stuck in this, didn't fine any specific solution for this.

Best Answer

You should use Magento\Eav\Model\Entity\Attribute\Source\Boolean source instead of 'Magento\Config\Model\Config\Source\Yesno'

Related Topic