Zend certified PHP/Magento developer

How to persist the value of a custom field on the customer_entity table?

I’m new to Magento 2 and to this forum.
I’m trying to add a newsletter subscription on the customer menu, just after the core one.

For that, i created a module “ACME_Newsletter”

  1. I added a custom field to the customer_entity table via a db_schema :

     <table name="customer_entity">
     <column
         xsi:type="boolean"
         name="acme_nl_subscription"
         nullable="false"
         default="false"
         comment="Acme Newsletter Subscription"
     />
    
  2. I created a layout that completes the existing one “customer_newsletter”

    <body>
        <referenceBlock name="customer_newsletter">
            <container name="customer.form.newsletter.extra">
                <block
                    class="ACMENewsletterBlockSubscription"
                    name="customer_form_newsletter_extra" as="acme_nl_subscription"
                    template="ACME_Newsletter::customer/form/subscription.phtml"
                />
            </container>
        </referenceBlock>
    </body>

Here is my template :

    <?php

/** @var ACMENewsletterBlockSubscription $block */
?>
<?= $block->getChildHtml('customer.form.newsletter.extra') ?>
<div class="field choice">
    <input type="checkbox" name="acme_nl_subscription" id="acme_nl_subscription" value="1"
           title="<?= $block->escapeHtmlAttr(__('ACME's Newsletter Subscription')) ?>"
        <?php if ($block->getCustomerSession()->getCustomer()->getAcmeNlSubscription()) : ?> checked="checked"<?php endif; ?>
           class="checkbox">
    <label for="acme_nl_subscription"
           class="label"><span><?= $block->escapeHtml(__('ACME's Newsletter Subscription')) ?></span></label>
</div>

And my block :

    <?php

namespace ACMENewsletterBlock;

use MagentoCustomerBlockNewsletter;

class Subscription extends Newsletter
{
    public function getCustomerSession()
    {
        return $this->customerSession;
    }

}

With all that I manage to retrieve the value stored in database.

Now I try to modify that value and to store it in db, within an after plugin on the MagentoNewsletterControllerManageSave::execute() method.

I can’t find the right way to write my method to persist this data.
For the moment, my plugin looks like this :

<?php

namespace ACMENewsletterPlugin;

use MagentoCustomerApiCustomerRepositoryInterface;
use MagentoCustomerModelSession;
use MagentoNewsletterControllerManageSave;
use MagentoFrameworkAppRequestInterface;
use MagentoCustomerModelResourceModelCustomerRepository as CustomerRepository;
use MagentoCustomerModelResourceModelCustomer as CustomerResource;
use MagentoCustomerModelCustomer as CustomerModel;

class AfterSavePlugin
{
    protected $customerSession;
    protected $request;
    protected $customerRepository;
    protected $customerRepositoryInterface;
    protected $customerResource;
    protected $customerModel;

    public function __construct(
        Session                     $customerSession,
        RequestInterface            $request,
        CustomerRepositoryInterface $customerRepositoryInterface,
        CustomerRepository          $customerRepository,
        CustomerResource            $customerResource,
        CustomerModel               $customerModel
    )
    {
        $this->customerSession = $customerSession;
        $this->request = $request;
        $this->customerRepository = $customerRepository;
        $this->customerRepositoryInterface = $customerRepositoryInterface;
        $this->customerResource = $customerResource;
        $this->customerModel = $customerModel;
    }

    public function afterExecute(Save $subject, $result)
    {
        $acmeNlSubscription = $this->request->getParam('acme_nl_subscription') ? (bool)$this->request->getParam('acme_nl_subscription') : 0;

        $sessionCustomer = $this->customerSession->getCustomer();
        $customerData = $sessionCustomer->getData();

        $repositoryCustomer = $this->customerRepository->getById($sessionCustomer->getId());

//        $modelCustomer->loadByEmail($sessionCustomer->getEmail());
        $modelCustomer = $this->customerModel;
        $modelCustomer->setData($customerData);

        $resourceCustomer = $this->customerResource->loadByEmail($modelCustomer, $modelCustomer->getEmail());

        $modelCustomer->save();

        return $result;
    }
}

Could a kind soul help me to take a step in my understanding of Adobe Commerce 2 (Magento 2) please?

What am I doing wrong? All comments are welcome, thank you!