Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] add fields items to contact menu #26540

Merged
merged 20 commits into from Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
173 changes: 173 additions & 0 deletions administrator/components/com_admin/script.php
Expand Up @@ -6076,4 +6076,177 @@ private function cleanJoomlaCache()
$model->setState('client_id', 1);
$model->clean();
}

/**
* Called after any type of action
*
* @param string $action Which action is happening (install|uninstall|discover_install|update)
* @param Installer $installer The class calling this method
*
* @return boolean True on success
*
* @since 3.7.0
alikon marked this conversation as resolved.
Show resolved Hide resolved
*/
public function postflight($action, $installer)
{
if ($action !== 'update')
{
return true;
}

if (empty($this->fromVersion) || version_compare($this->fromVersion, '4.0.0', 'ge'))
{
return true;
}

$db = Factory::getDbo();
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_menus/Table/');

$tableItem = new \Joomla\Component\Menus\Administrator\Table\MenuTable($db);

// Check for the Contact parent Id Menu Item
$keys = [
'menutype' => 'main',
'type' => 'component',
'title' => 'com_contact',
'parent_id' => 1,
'client_id' => 1,
];

$contactMenuitem = $tableItem->load($keys);

if (!$contactMenuitem)
{
return false;
}

$parentId = $tableItem->id;
$componentId = ExtensionHelper::getExtensionRecord('com_fields')->extension_id;

// Add Contact Fields Menu Items.
$menuItems = [
[
'menutype' => 'main',
'title' => '-',
'alias' => microtime(true),
'note' => '',
'path' => '',
'link' => '#',
'type' => 'separator',
'published' => 1,
'parent_id' => $parentId,
'level' => 2,
'component_id' => $componentId,
'checked_out' => 0,
'checked_out_time' => null,
'browserNav' => 0,
'access' => 0,
'img' => '',
'template_style_id' => 0,
'params' => '{}',
'home' => 0,
'language' => '*',
'client_id' => 1,
'publish_up' => null,
'publish_down' => null,
],
[
'menutype' => 'main',
'title' => 'mod_menu_fields',
'alias' => 'Contact Custom Fields',
'note' => '',
'path' => 'contact/Custom Fields',
'link' => 'index.php?option=com_fields&context=com_contact.contact',
'type' => 'component',
'published' => 1,
'parent_id' => $parentId,
'level' => 2,
'component_id' => $componentId,
'checked_out' => 0,
'checked_out_time' => null,
'browserNav' => 0,
'access' => 0,
'img' => '',
'template_style_id' => 0,
'params' => '{}',
'home' => 0,
'language' => '*',
'client_id' => 1,
'publish_up' => null,
'publish_down' => null,
],
[
'menutype' => 'main',
'title' => 'mod_menu_fields_group',
'alias' => 'Contact Custom Fields Group',
'note' => '',
'path' => 'contact/Custom Fields Group',
'link' => 'index.php?option=com_fields&view=groups&context=com_contact.contact',
'type' => 'component',
'published' => 1,
'parent_id' => $parentId,
'level' => 2,
'component_id' => $componentId,
'checked_out' => 0,
'checked_out_time' => null,
'browserNav' => 0,
'access' => 0,
'img' => '',
'template_style_id' => 0,
'params' => '{}',
'home' => 0,
'language' => '*',
'client_id' => 1,
'publish_up' => null,
'publish_down' => null,
]
];

foreach ($menuItems as $menuItem)
{
// Check an existing record
$keys = [
'menutype' => $menuItem['menutype'],
'type' => $menuItem['type'],
'title' => $menuItem['title'],
'parent_id' => $menuItem['parent_id'],
'client_id' => $menuItem['client_id'],
];

if ($tableItem->load($keys))
{
continue;
}

$newTableItem = new \Joomla\Component\Menus\Administrator\Table\MenuTable($db);
alikon marked this conversation as resolved.
Show resolved Hide resolved

// Bind the data.
alikon marked this conversation as resolved.
Show resolved Hide resolved
if (!$newTableItem->bind($menuItem))
{
return false;
}

$newTableItem->setLocation($menuItem['parent_id'], 'last-child');

// Check the data.
if (!$newTableItem->check())
{
return false;
}

// Store the data.
if (!$newTableItem->store())
{
return false;
}

// Rebuild the tree path.
if (!$newTableItem->rebuildPath($newTableItem->id))
{
return false;
}
}

return true;
}
}
27 changes: 0 additions & 27 deletions administrator/components/com_contact/Helper/ContactHelper.php
Expand Up @@ -11,9 +11,7 @@

defined('_JEXEC') or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Language\Text;

/**
* Contact component helper.
Expand All @@ -22,29 +20,4 @@
*/
class ContactHelper extends ContentHelper
{
/**
* Configure the Linkbar.
*
* @param string $vName The name of the active view.
*
* @return void
*
* @since 1.6
*/
public static function addSubmenu($vName)
{
if (ComponentHelper::isEnabled('com_fields') && ComponentHelper::getParams('com_contact')->get('custom_fields_enable', '1'))
{
\JHtmlSidebar::addEntry(
Text::_('JGLOBAL_FIELDS'),
'index.php?option=com_fields&context=com_contact.contact',
$vName == 'fields.fields'
);
\JHtmlSidebar::addEntry(
Text::_('JGLOBAL_FIELD_GROUPS'),
'index.php?option=com_fields&view=groups&context=com_contact.contact',
$vName == 'fields.groups'
);
}
}
}