Skip to content

Conversation

alancarvalho
Copy link

Brief

This module works seamlessly by recording administrative actions for core Magento modules, and we could extend it to custom modules/features in a way that eliminates any plugins or overrides to apply this feature.

Usage

With this PR code, we can easily handle this by adding this code below.

Create etc/adminactivity.xml inside a custom module:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Catgento_AdminActivity:etc/adminactivity.xsd">
    <modules>
        <module name="foo_bar">
            <label translate="true">Foo Bar</label>
            <models>
                <class name="Foo\Bar\Model\Example" />
            </models>
            <events>
                <event controller_action="foo_bar_index_save" action_alias="save" />
                <event controller_action="foo_bar_index_edit" action_alias="edit" />
                <event controller_action="foo_bar_index_delete" action_alias="delete" />
            </events>
            <config>
                <trackfield method="Foo\Bar\Model\AdminActivity::getFieldData" />
                <configpath constant="Foo\Bar\Model\AdminActivity::CONFIG_PATH" />
                <editurl url="{{module}}/{{controller}}/edit/id/{{id}}" />
                <itemfield field="name" />
            </config>
        </module>
    </modules>
</config>

Add a class that will handle trackfield and configpath attributes from adminactivity.xml:

<?php
declare(strict_types=1);

namespace Foo\Bar\Model;

class AdminActivity
{
    /**
     * Path to the configuration for admin activity logging.
     */
    public const CONFIG_PATH = 'admin/activity/log/foo_bar';

    /**
     * Get excluded fields from the activity log.
     *
     * @return array An array containing the names of fields to be excluded.
     */
    public static function getFieldData(): array
    {
        return [
            'form_key',
            'entity_id',
            'check_if_is_new',
        ];
    }
}

Issues fixed

  • The "Configuration" URL set in etc/adminhtml/menu.xml is pointing to the wrong path
  • The default settings paths are incorrect in etc/config.xml

Contribution

Monsoon Consulting

Thank you!

@monteshot
Copy link

Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants