Magento2 - List of all coreRegistry register calls

This on going updated post lists all calls to coreRegistry->register() in Magento2. A registry cheat sheet.

Current version: 2.0.13 / Feb 13, 2017

Why is this useful?

If you want to extend any block, model, helper or listen to a specific event you might likely need to use the current product, category, cms page, cms block, order, quote, etc. model.

I’ve seen a lot of bad written Magento1 code where developers instantiated over and over again new objects of already available objects only to access a few properties. This slows down everything.

After you have identified your event or figured out where to integrate the plugin for the integration calls you should figure out the current route and check here if the main object is globally available in the registry.

The registry acts as a message channel between different objects/areas. It lets you communicate data from the controller to a helper, a block or another model. Of course you can communicate in any direction.

If you want to create registry entries for your modules, please do not abuse the registry for simple values. Create your own objects and share them via singleton patterns.

How can I use this feature in my code?

Here is an example code on how to use the coreRegistry. This fictional class creates new tabs in the catalog/category section. Each tab lists the best sold products per category.

The registry entry will be created here: app/code/Magento/Catalog/Controller/Adminhtml/Category.php#L67

namespace MyNamespace\MyModule\Block\Adminhtml\CategorySales;

class BestSalesTabs extends \Magento\Backend\Block\Widget\Tabs
{

    /**
     * Core registry
     *
     * @var \Magento\Framework\Registry|null
     */
    protected $_coreRegistry = null;

    /**
     * @param \Magento\Backend\Block\Template\Context $context
     * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
     * @param \Magento\Backend\Model\Auth\Session $authSession
     * @param \Magento\Framework\Registry $registry
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Framework\Json\EncoderInterface $jsonEncoder,
        \Magento\Backend\Model\Auth\Session $authSession,
        \Magento\Framework\Registry $registry,
        array $data = []
    ) {
        $this->_coreRegistry = $registry;
        parent::__construct($context, $jsonEncoder, $authSession, $data);
    }

    /**
     * Retrieve category object
     *
     * @return \Magento\Catalog\Model\Category
     */
    public function getCategory()
    {
        return $this->_coreRegistry->registry('current_category');
    }

    /**
     * Prepare Layout Content
     *
     * @return $this
     */
    protected function _prepareLayout()
    {
        $categoryAttributes = $this->getCategory()->getAttributes();
        if (!$this->getCategory()->getId()) {
    ...

Do NOT access the registry via the objectManager:

$this->_objectManager->get('Magento\Framework\Registry')->registry('current_category');

This is an anti-pattern.

The usage of objectManager as service locator leads to highly coupled code and hidden dependencies. Also the ability to configure specific arguments for the client that uses the OM directly is lost.

The OM can be used only in composition root of application (Bootstrap) and for unserialization of entities with service dependencies.

Please use your browsers search function!

File / Code
app/code/Magento/Authorizenet/Controller/Adminhtml/Authorizenet/Directpost/Payment/Redirect.php
NO_MATCH
$this->_coreRegistry->register(Iframe
app/code/Magento/Authorizenet/Controller/Directpost/Payment/Redirect.php
NO_MATCH
$this->_coreRegistry->register(Iframe
app/code/Magento/Authorizenet/Controller/Directpost/Payment.php
NO_MATCH
$this->_coreRegistry->register(Iframe
app/code/Magento/Authorizenet/Observer/SaveOrderAfterSubmitObserver.php
directpost_order
$this->coreRegistry->register('directpost_order', $order, true);
app/code/Magento/Backend/Controller/Adminhtml/System/Design/Edit.php
design
$this->_coreRegistry->register('design', $design);
app/code/Magento/Backend/Controller/Adminhtml/System/Store/EditGroup.php
store_type
$this->_coreRegistry->register('store_type', 'group');
app/code/Magento/Backend/Controller/Adminhtml/System/Store/EditStore.php
store_post_data
$this->_coreRegistry->register('store_post_data', $this->_getSession()->getPostData());
app/code/Magento/Backend/Controller/Adminhtml/System/Store/EditStore.php
store_type
$this->_coreRegistry->register('store_type', 'store');
app/code/Magento/Backend/Controller/Adminhtml/System/Store/EditStore.php
store_action
$this->_coreRegistry->register('store_action', 'edit');
app/code/Magento/Backend/Controller/Adminhtml/System/Store/EditStore.php
store_data
$this->_coreRegistry->register('store_data', $model);
app/code/Magento/Backend/Controller/Adminhtml/System/Store/EditWebsite.php
store_type
$this->_coreRegistry->register('store_type', 'website');
app/code/Magento/Backend/Controller/Adminhtml/System/Store/NewGroup.php
store_type
$this->_coreRegistry->register('store_type', 'group');
app/code/Magento/Backend/Controller/Adminhtml/System/Store/NewStore.php
store_type
$this->_coreRegistry->register('store_type', 'store');
app/code/Magento/Backend/Controller/Adminhtml/System/Store/NewStore.php
store_action
$this->_coreRegistry->register('store_action', 'add');
app/code/Magento/Backend/Controller/Adminhtml/System/Store/NewWebsite.php
store_type
$this->_coreRegistry->register('store_type', 'website');
app/code/Magento/Backup/Controller/Adminhtml/Index/Create.php
backup_manager
$this->_coreRegistry->register('backup_manager', $backupManager);
app/code/Magento/Backup/Controller/Adminhtml/Index/MassDelete.php
backup_manager
$this->_coreRegistry->register('backup_manager', $resultData);
app/code/Magento/Backup/Controller/Adminhtml/Index/Rollback.php
backup_manager
$this->_coreRegistry->register('backup_manager', $backupManager);
app/code/Magento/Backup/Cron/SystemBackup.php
backup_manager
$this->_coreRegistry->register('backup_manager', $backupManager);
app/code/Magento/Bundle/Model/Product/CatalogPrice.php
rule_data
$this->coreRegistry->register(
    'rule_data',
    new \Magento\Framework\DataObject(
[
    'store_id' => $product->getStoreId(),
    'website_id' => $product->getWebsiteId(),
    'customer_group_id' => $product->getCustomerGroupId(),
]
    ));
app/code/Magento/Catalog/Block/Adminhtml/Category/AbstractCategory.php
root
$this->_coreRegistry->register('root', $root);
app/code/Magento/Catalog/Block/Adminhtml/Category/AbstractCategory.php
root
$this->_coreRegistry->register('root', $root);
app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Main.php
attribute_type_hidden_fields
$this->_coreRegistry->register('attribute_type_hidden_fields', $_hiddenFields);
app/code/Magento/Catalog/Block/Product/View.php
product
$this->_coreRegistry->register('product', $product);
app/code/Magento/Catalog/Controller/Adminhtml/Category/Widget/CategoriesJson.php
category
$this->_coreRegistry->register('category', $category);
app/code/Magento/Catalog/Controller/Adminhtml/Category/Widget/CategoriesJson.php
current_category
$this->_coreRegistry->register('current_category', $category);
app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Edit.php
entity_attribute
$this->_coreRegistry->register('entity_attribute', $model);
app/code/Magento/Catalog/Controller/Adminhtml/Product/Set/Edit.php
current_attribute_set
$this->_coreRegistry->register('current_attribute_set', $attributeSet);
app/code/Magento/Catalog/Controller/Adminhtml/Product/Set.php
entityType
$this->_coreRegistry->register(
    'entityType',
    $this->_objectManager->create('Magento\Catalog\Model\Product')->getResource()->getTypeId());
app/code/Magento/Catalog/Controller/Category/View.php
current_category
$this->_coreRegistry->register('current_category', $category);
app/code/Magento/Catalog/Helper/Product/Composite.php
composite_update_result
$this->_coreRegistry->register('composite_update_result', $updateResult);
app/code/Magento/Catalog/Helper/Product/Composite.php
current_product
$this->_coreRegistry->register('current_product', $product);
app/code/Magento/Catalog/Helper/Product/Composite.php
product
$this->_coreRegistry->register('product', $product);
app/code/Magento/Catalog/Helper/Product/Composite.php
NO_MATCH
$this->_coreRegistry->register(RegistryConstants
app/code/Magento/Catalog/Helper/Product/Composite.php
composite_configure_result_error_message
$this->_coreRegistry->register('composite_configure_result_error_message', $e->getMessage());
app/code/Magento/Catalog/Helper/Product.php
current_category
$this->_coreRegistry->register('current_category', $category);
app/code/Magento/Catalog/Helper/Product.php
current_product
$this->_coreRegistry->register('current_product', $product);
app/code/Magento/Catalog/Helper/Product.php
product
$this->_coreRegistry->register('product', $product);
app/code/Magento/Catalog/Model/Layer/Filter/DataProvider/Category.php
current_category_filter
$this->coreRegistry->register('current_category_filter', $category, true);
app/code/Magento/Catalog/Model/Product/Attribute/Source/Inputtype.php
attribute_type_hidden_fields
$this->_coreRegistry->register('attribute_type_hidden_fields', $_hiddenFields);
app/code/Magento/Catalog/Model/Product/Type/AbstractType.php
used_super_product_
$this->_coreRegistry->register('used_super_product_' . $superProductId, $superProduct);
app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Edit.php
current_promo_catalog_rule
$this->_coreRegistry->register('current_promo_catalog_rule', $model);
app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Widget/CategoriesJson.php
category
$this->_coreRegistry->register('category', $category);
app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Widget/CategoriesJson.php
current_category
$this->_coreRegistry->register('current_category', $category);
app/code/Magento/CheckoutAgreements/Controller/Adminhtml/Agreement/Edit.php
checkout_agreement
$this->_coreRegistry->register('checkout_agreement', $agreementModel);
app/code/Magento/Cms/Controller/Adminhtml/Block/Edit.php
cms_block
$this->_coreRegistry->register('cms_block', $model);
app/code/Magento/Cms/Controller/Adminhtml/Page/Edit.php
cms_page
$this->_coreRegistry->register('cms_page', $model);
app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images.php
storage
$this->_coreRegistry->register('storage', $storage);
app/code/Magento/Config/Model/Config/Source/Email/Template.php
config_system_email_template
$this->_coreRegistry->register('config_system_email_template', $collection);
app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Newsletter.php
subscriber
$this->_coreRegistry->register('subscriber', $subscriber);
app/code/Magento/Customer/Controller/Adminhtml/Group/NewAction.php
NO_MATCH
$this->_coreRegistry->register(RegistryConstants
app/code/Magento/Customer/Controller/Adminhtml/Index/Newsletter.php
subscriber
$this->_coreRegistry->register('subscriber', $subscriber);
app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php
NO_MATCH
$this->_coreRegistry->register(RegistryConstants
app/code/Magento/Customer/Controller/Adminhtml/Index.php
NO_MATCH
$this->_coreRegistry->register(RegistryConstants
app/code/Magento/Customer/Observer/AfterAddressSaveObserver.php
NO_MATCH
$this->_coreRegistry->register(self
app/code/Magento/Customer/Observer/AfterAddressSaveObserver.php
NO_MATCH
$this->_coreRegistry->register(self
app/code/Magento/Customer/Observer/BeforeAddressSaveObserver.php
NO_MATCH
$this->_coreRegistry->register(self
app/code/Magento/Customer/Observer/BeforeAddressSaveObserver.php
NO_MATCH
$this->_coreRegistry->register(self
app/code/Magento/Email/Controller/Adminhtml/Email/Template.php
email_template
$this->_coreRegistry->register('email_template', $model);
app/code/Magento/Email/Controller/Adminhtml/Email/Template.php
current_email_template
$this->_coreRegistry->register('current_email_template', $model);
app/code/Magento/Newsletter/Block/Adminhtml/Subscriber/Grid/Filter/Website.php
website_collection
$this->_coreRegistry->register('website_collection', $this->_websiteCollection);
app/code/Magento/Newsletter/Controller/Adminhtml/Queue/Edit.php
current_queue
$this->_coreRegistry->register('current_queue', $this->_objectManager->get('Magento\Newsletter\Model\Queue'));
app/code/Magento/Newsletter/Controller/Adminhtml/Template/Edit.php
_current_template
$this->_coreRegistry->register('_current_template', $model);
app/code/Magento/Paypal/Controller/Adminhtml/Billing/Agreement/CustomerGrid.php
NO_MATCH
$this->_coreRegistry->register(RegistryConstants
app/code/Magento/Paypal/Controller/Adminhtml/Billing/Agreement.php
current_billing_agreement
$this->_coreRegistry->register('current_billing_agreement', $agreementModel);
app/code/Magento/Paypal/Controller/Adminhtml/Paypal/Reports/Details.php
current_transaction
$this->_coreRegistry->register('current_transaction', $row);
app/code/Magento/Paypal/Controller/Billing/Agreement.php
current_billing_agreement
$this->_coreRegistry->register('current_billing_agreement', $billingAgreement);
app/code/Magento/Paypal/Controller/Transparent/Response.php
NO_MATCH
$this->coreRegistry->register(Iframe
app/code/Magento/Paypal/Observer/SaveOrderAfterSubmitObserver.php
hss_order
$this->_coreRegistry->register('hss_order', $order, true);
app/code/Magento/Review/Block/Adminhtml/Edit.php
ret
$this->_coreRegistry->register('ret', 'pending');
app/code/Magento/Review/Block/Adminhtml/Edit.php
review_data
$this->_coreRegistry->register('review_data', $reviewData);
app/code/Magento/Review/Block/Adminhtml/Rating/Edit.php
rating_data
$this->_coreRegistry->register('rating_data', $ratingData);
app/code/Magento/Review/Controller/Adminhtml/Product/Pending.php
usePendingFilter
$this->coreRegistry->register('usePendingFilter', true);
app/code/Magento/Review/Controller/Adminhtml/Product/Pending.php
usePendingFilter
$this->coreRegistry->register('usePendingFilter', true);
app/code/Magento/Review/Controller/Adminhtml/Rating.php
entityId
$this->coreRegistry->register(
    'entityId',
    $this->_objectManager->create('Magento\Review\Model\Rating\Entity')->getIdByCode('product'));
app/code/Magento/Review/Controller/Product/ListAction.php
productId
$this->coreRegistry->register('productId', $product->getId());
app/code/Magento/Review/Controller/Product/View.php
current_review
$this->coreRegistry->register('current_review', $review);
app/code/Magento/Review/Controller/Product.php
current_category
$this->coreRegistry->register('current_category', $category);
app/code/Magento/Review/Controller/Product.php
current_product
$this->coreRegistry->register('current_product', $product);
app/code/Magento/Review/Controller/Product.php
product
$this->coreRegistry->register('product', $product);
app/code/Magento/Sales/Controller/AbstractController/PrintCreditmemo.php
current_order
$this->_coreRegistry->register('current_order', $order);
app/code/Magento/Sales/Controller/AbstractController/PrintCreditmemo.php
current_creditmemo
$this->_coreRegistry->register('current_creditmemo', $creditmemo);
app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php
current_order
$this->_coreRegistry->register('current_order', $order);
app/code/Magento/Sales/Controller/AbstractController/PrintInvoice.php
current_invoice
$this->_coreRegistry->register('current_invoice', $invoice);
app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php
current_order
$this->_coreRegistry->register('current_order', $order);
app/code/Magento/Sales/Controller/AbstractController/PrintShipment.php
current_shipment
$this->_coreRegistry->register('current_shipment', $shipment);
app/code/Magento/Sales/Controller/Adminhtml/Order/Address.php
order_address
$this->_coreRegistry->register('order_address', $address);
app/code/Magento/Sales/Controller/Adminhtml/Order/Status/Edit.php
current_status
$this->_coreRegistry->register('current_status', $status);
app/code/Magento/Sales/Controller/Adminhtml/Order/Status/NewAction.php
current_status
$this->_coreRegistry->register('current_status', $status);
app/code/Magento/Sales/Controller/Adminhtml/Order.php
sales_order
$this->_coreRegistry->register('sales_order', $order);
app/code/Magento/Sales/Controller/Adminhtml/Order.php
current_order
$this->_coreRegistry->register('current_order', $order);
app/code/Magento/Sales/Controller/Adminhtml/Transactions.php
current_transaction
$this->_coreRegistry->register('current_transaction', $txn);
app/code/Magento/Sales/Controller/Guest/PrintCreditmemo.php
current_creditmemo
$this->_coreRegistry->register('current_creditmemo', $creditmemo);
app/code/Magento/Sales/Controller/Guest/PrintInvoice.php
current_invoice
$this->_coreRegistry->register('current_invoice', $invoice);
app/code/Magento/Sales/Controller/Guest/PrintShipment.php
current_shipment
$this->_coreRegistry->register('current_shipment', $shipment);
app/code/Magento/Sales/Helper/Guest.php
current_order
$this->coreRegistry->register('current_order', $order);
app/code/Magento/Sales/Model/AdminOrder/Create.php
rule_data
$this->_coreRegistry->register(
    'rule_data',
    new \Magento\Framework\DataObject(
[
    'store_id' => $this->_session->getStore()->getId(),
    'website_id' => $this->_session->getStore()->getWebsiteId(),
    'customer_group_id' => $this->getCustomerGroupId()
]
    ));
app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Edit.php
current_promo_quote_rule
$this->_coreRegistry->register('current_promo_quote_rule', $model);
app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote.php
current_promo_quote_rule
$this->_coreRegistry->register(
    'current_promo_quote_rule',
    $this->_objectManager->create('Magento\SalesRule\Model\Rule'));
app/code/Magento/Search/Controller/Adminhtml/Term/Edit.php
current_catalog_search
$this->coreRegistry->register('current_catalog_search', $model);
app/code/Magento/SendFriend/Controller/Product/Sendmail.php
current_category
$this->_coreRegistry->register('current_category', $category);
app/code/Magento/SendFriend/Controller/Product.php
product
$this->_coreRegistry->register('product', $product);
app/code/Magento/Shipping/Controller/Tracking/Popup.php
current_shipping_info
$this->_coreRegistry->register('current_shipping_info', $shippingInfoModel);
app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Edit.php
sitemap_sitemap
$this->_coreRegistry->register('sitemap_sitemap', $model);
app/code/Magento/Tax/Controller/Adminhtml/Rate/Add.php
NO_MATCH
$this->_coreRegistry->register(
    RegistryConstants
app/code/Magento/Tax/Controller/Adminhtml/Rate/Edit.php
NO_MATCH
$this->_coreRegistry->register(RegistryConstants
app/code/Magento/Tax/Controller/Adminhtml/Rule/Edit.php
tax_rule_id
$this->_coreRegistry->register('tax_rule_id', $taxRuleId);
app/code/Magento/Tax/Controller/Adminhtml/Rule/Edit.php
tax_rule_form_data
$this->_coreRegistry->register('tax_rule_form_data', $data);
app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/Edit.php
current_theme
$this->_coreRegistry->register('current_theme', $theme);
app/code/Magento/User/Block/Role/Grid/User.php
RID
$this->_coreRegistry->register('RID', $roleId);
app/code/Magento/User/Controller/Adminhtml/User/Edit.php
permissions_user
$this->_coreRegistry->register('permissions_user', $model);
app/code/Magento/User/Controller/Adminhtml/User/Role.php
current_role
$this->_coreRegistry->register('current_role', $role);
app/code/Magento/User/Controller/Adminhtml/User/RolesGrid.php
permissions_user
$this->_coreRegistry->register('permissions_user', $model);
app/code/Magento/Variable/Controller/Adminhtml/System/Variable.php
current_variable
$this->_coreRegistry->register('current_variable', $variable);
app/code/Magento/Widget/Controller/Adminhtml/Widget/Index.php
skip_widgets
$this->_coreRegistry->register('skip_widgets', $skipped);
app/code/Magento/Widget/Controller/Adminhtml/Widget/Instance.php
current_widget_instance
$this->_coreRegistry->register('current_widget_instance', $widgetInstance);
app/code/Magento/Wishlist/Controller/Index/Configure.php
wishlist_item
$this->_coreRegistry->register('wishlist_item', $item);
app/code/Magento/Braintree/Model/PaymentMethod.php
NO_MATCH
$this->_registry->register(self
app/code/Magento/Catalog/Model/Category.php
_category_is_anchor_attribute
$this->_registry->register('_category_is_anchor_attribute', $model);
app/code/Magento/CatalogSearch/Model/Advanced.php
advanced_search_conditions
$this->_registry->register('advanced_search_conditions', $allConditions);
app/code/Magento/Config/Model/Config/Backend/Admin/Custompath.php
custom_admin_path_redirect
$this->_registry->register('custom_admin_path_redirect', true, true);
app/code/Magento/GoogleAdwords/Observer/SetConversionValueObserver.php
NO_MATCH
$this->_registry->register(
    \Magento\GoogleAdwords\Helper\Data
app/code/Magento/Integration/Controller/Adminhtml/Integration/Delete.php
NO_MATCH
$this->_registry->register(self
app/code/Magento/Integration/Controller/Adminhtml/Integration/Edit.php
NO_MATCH
$this->_registry->register(self
app/code/Magento/Integration/Controller/Adminhtml/Integration/NewAction.php
NO_MATCH
$this->_registry->register(self
app/code/Magento/Integration/Controller/Adminhtml/Integration/PermissionsDialog.php
NO_MATCH
$this->_registry->register(self
app/code/Magento/Integration/Controller/Adminhtml/Integration/TokensDialog.php
NO_MATCH
$this->_registry->register(
    self
app/code/Magento/Catalog/Controller/Adminhtml/Category.php
category
$this->_objectManager->get('Magento\Framework\Registry')->register('category', $category);
app/code/Magento/Catalog/Controller/Adminhtml/Category.php
current_category
$this->_objectManager->get('Magento\Framework\Registry')->register('current_category', $category);

Related posts

comments powered by Disqus