How to use custom controls on administrative product and category pages

The class \Magento\Backend\Block\Widget\Form has a protected _getAdditionalElementTypes method:

https://github.com/magento/magento2/blob/d59a6fd3013833ac55f6c50a4cf668ef7adc2294/app/code/Magento/Backend/Block/Widget/Form.php#L265-L268

A descendant can override this method to support displaying custom controls.

https://github.com/magento/magento2/blob/d59a6fd3013833ac55f6c50a4cf668ef7adc2294/app/code/Magento/Backend/Block/Widget/Form.php#L254

The possibility is used by administrative product and categories screens.

\Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Attributes::_getAdditionalElementTypes():

https://github.com/magento/magento2/blob/d59a6fd3013833ac55f6c50a4cf668ef7adc2294/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Attributes.php#L138-L158

As you can seem the administrative product form adds custom form element types: price, weight, gallery, image, boolean, textarea.

Then it fires the event adminhtml_catalog_product_edit_element_types:

https://github.com/magento/magento2/blob/d59a6fd3013833ac55f6c50a4cf668ef7adc2294/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Attributes.php#L151

A custom extension can handle the event and add its custom controls (form element types):

<?xml version='1.0'?>
<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd'>
	<event name='adminhtml_catalog_product_edit_element_types'>
		<observer
			name='Dfe\Markdown\Observer\ElementTypes'
			instance='Dfe\Markdown\Observer\ElementTypes'
		/>
	</event>
</config>
<?php
namespace Dfe\Markdown\Observer;
use Magento\Framework\Event\ObserverInterface;
class ElementTypes implements ObserverInterface {
	/**
	 * @override
	 * @see ObserverInterface::execute()
	 * @used-by \Magento\Framework\Event\Invoker\InvokerDefault::_callObserverMethod()
	 * @see \Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Attributes::_getAdditionalElementTypes()
	 * https://github.com/magento/magento2/blob/0be91a56d050791ac0b67a47185d79df31e79329/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Attributes.php#L151
		$response = new \Magento\Framework\DataObject();
		$response->setTypes([]);
		$this->_eventManager->dispatch(
			'adminhtml_catalog_product_edit_element_types', ['response' => $response]
		);
	 * https://3v4l.org/UidhW
	 * @param \Magento\Framework\Event\Observer $o
	 * @return void
	 */
	public function execute(\Magento\Framework\Event\Observer $o) {
		if (\Dfe\Markdown\Settings::s()->enable()) {
			$o['response']['types'] = ['textarea' => 'Dfe\Markdown\FormElement'];
		}
	}
}

It works for administrative product page but there is a problem for administrative category page: the corresponding category edit form does not fire any events:
https://github.com/magento/magento2/issues/2165

While it is not fixed in the core I use a workaround solution: override the admin category form class and fire the event my myself:

<?xml version='1.0'?>
<config
	xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
	xsi:noNamespaceSchemaLocation='../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd'
>
	<preference
		for='Magento\Catalog\Block\Adminhtml\Category\Tab\Attributes'
		type='Df\Catalog\Block\Adminhtml\Category\Tab\Attributes'
	/>
</config>
<?php
namespace Df\Catalog\Block\Adminhtml\Category\Tab;
class Attributes extends \Magento\Catalog\Block\Adminhtml\Category\Tab\Attributes {
	/**
	 * @override
	 * @see \Magento\Catalog\Block\Adminhtml\Category\Tab\Attributes::_getAdditionalElementTypes()
	 * @return string[]
	 */
	protected function _getAdditionalElementTypes() {
		/** @var string[] $result */
		$result = parent::_getAdditionalElementTypes();
		$response = new \Magento\Framework\DataObject();
		$response['types'] = [];
		$this->_eventManager->dispatch(
			'adminhtml_catalog_category_edit_element_types', ['response' => $response]
		);
		foreach ($response['types'] as $typeName => $typeClass) {
			/** @var string $typeName */
			/** @var string $typeClass */
			$result[$typeName] = $typeClass;
		}
		return $result;
	}
}
<?xml version='1.0'?>
<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='../../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd'>
	<event name='adminhtml_catalog_category_edit_element_types'>
		<observer
			name='Dfe\Markdown\Observer\ElementTypes'
			instance='Dfe\Markdown\Observer\ElementTypes'
		/>
	</event>
</config>

This might be more what I was looking for, this is great for overriding all of one field type. What if I wanted to change the helper (or input_renderer) for an existing attribute?