Getting Menu Inheritance to Work in a Multi-Module Maven Site - maven

I have a question about constructing a Maven site with a parent POM file and sub-modules. I am having trouble getting relative links in inherited module sites to work when the menu is inherited from a parent POM.
I have a project structure as follows:
modules/pom.xml
parent/
module1/
module2/
etc.
So with this configuration I end up with a site that looks like:
base-site/
module1/
module2/
The reactor build from modules/pom.xml generates the top-level website, and each of the modules also has a site generated.
Each of the modules inherits this site.xml file from the parent (for example):
<project>
<body>
<menu name="Module" inherit="top">
<item name="Summary" href="./project-summary.html"/>
</menu>
<menu name="Module" ref="reports" inherit="bottom" />
</body>
</project>
The menu referencing the standard Maven generated "reports" works fine.
But the href to project-summary.html ends up pointing back at the top site and not the child.
I have seen some similar issues on Stackoverflow having to do with constructing an inherited menu, but I did not find exact information on how to get these links to point to content in the child site and not the parent. It may be possible that I am misunderstanding what the menu inheritance is supposed to accomplish here.
Basically, I want the menu links to generated content in the child sites to look like:
<item name="Summary" href="./module1/project-summary.html"/>
Okay, so I thought, let me try to use filtering to accomplish this like from my parent POM using something like:
<item name="Summary" href="./${project.artifactId}/project-summary.html"/>
But that does not work because the parent POM's name gets substituted here instead of the child project's name.
In this case, perhaps I need site a custom site.xml for each module, but I would like to avoid this as there are something like 15 of them, and they will mostly be identical in terms of sharing about 8 or 9 different (relative) menu links. Most projects would not need their own site.xml file. So ideally I'd like the parent to define all the defaults with the child POMs adding a few additional menus.
In order to do this, am I stuck with using the "reports" ref and its default layout? Or can I list these explicitly as menu items in the parent's site.xml file and get those references to work somehow?
I hope that's clear. Thanks.

I've the same need as you.
I'll use the gmaven-plugin with a script (during the generate resource phase) that iterates in parent and copy src/site/site.xml in the current project if any.
Here's my script (Here's I'm just copying a parent site.xml file if a 'readme.md' file is present on the module):
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>execute</goal>
</goals>
<phase>pre-site</phase>
</execution>
</executions>
<configuration>
<scripts>
<script> <![CDATA[
import java.io.BufferedWriter
import java.io.File
import java.nio.charset.Charset
import java.nio.file.StandardCopyOption
import java.nio.file.Files
import java.nio.file.StandardOpenOption
String siteXmlPath = "src/site/site.xml"
String readme_file = "readme.md"
String currentPath = "${project.basedir}"
if (new File(currentPath + "/" + readme_file).exists() && !(new File(currentPath + "/" + siteXmlPath).exists())) {
while (!(new File(currentPath + "/" + siteXmlPath).exists())) {
currentPath = currentPath + "/.."
if (new File(currentPath + "/" + siteXmlPath).exists()) {
Files.copy(new File(currentPath + "/" + siteXmlPath).toPath(), new File("${project.basedir}/" + siteXmlPath).toPath(), StandardCopyOption.REPLACE_EXISTING)
File newlyCreatedFile = new File("${project.basedir}/" + siteXmlPath)
BufferedWriter newFileWriter = Files.newBufferedWriter(newlyCreatedFile.toPath(), Charset.defaultCharset(), StandardOpenOption.APPEND)
newFileWriter.append("<!-- #generated -->")
newFileWriter.close()
} else if (!(new File(currentPath + "/pom.xml").exists())) { break; }
}
} ]]>
</script>
</scripts>
</configuration>
</plugin>
Regards

Related

Adding title to cms footer block

I added a second footer block with links by adding the following code to my default.xml in my theme:
(app/design/frontend///Magento_Theme/layout/default.xml)
<referenceContainer name="footer">
<block class="Magento\Framework\View\Element\Html\Links" name="footer_links_custom">
<arguments>
<argument name="css_class" xsi:type="string">footer links</argument>
</arguments>
</block>
</referenceContainer>
<referenceBlock name="footer_links_custom">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="2custom-link">
<arguments>
<argument name="label" xsi:type="string">Custom Links</argument>
<argument name="path" xsi:type="string">page-url</argument>
</arguments>
</block>
</referenceBlock>
What is the easiest way to add a title to the my footer_links_custom block, is there any way to do this in a simple manner? I've tried setting an argument "title" but that didn't work obviously. Is there any way we can know all the attributes there are for a certain block? (css_class, label, path, ...)
Is there no .phtml file for the footer links block?
Magento 2 leaves me behind with a lot of questions...
Thanks for the help!
In /magento/app/design/frontend/theme/theme/Magento_Theme/ You can set up the structure needed for this. and documentation to help can be found at:
http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/bk-frontend-dev-guide.html
In Magento_Theme/layout/default.xml you will find your block declarations, such as what you listed above already.
In Magento_Theme/Block/Html/Footer.php you can set up your controller with your Mage interface, such as...
class Footer extends \Magento\Framework\View\Element\Template implements \Magento\Framework\DataObject\IdentityInterface
{
protected $_copyright;
....
public function getCopyright()
{
if (!$this->_copyright) {
$this->_copyright = $this->_scopeConfig->getValue(
'design/footer/copyright',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
return $this->_copyright;
}
...
Magento_Theme/templates/html is where you can put your .phtml that your used to working with in Magento 1. Its not the exact same code obviously, but the idea is still the same here. for example, here is a footer that isn't code but stored in a db:
$om = \Magento\Framework\App\ObjectManager::getInstance();
$manager = $om->get('Magento\Store\Model\StoreManagerInterface');
$store = $manager->getStore(null)->getName();
$connection = $om->create('\Magento\Framework\App\ResourceConnection');
$conn = $connection->getConnection();
$select = $conn->select()
->from(
['o' => 'xyz_sitedata_items'],
['footer']
)
->where('o.storename=?', $store);
$data = $conn->fetchAll($select);
echo $data[0]['footer'];
for the record, using the object manager like this isn't recommended.
for a specific answer to the question posed, i would look to adding code to your footer.php. you can add data in with the construct, as well as reading all the data for the associated block there.

magento: remove page layouts

In magento the following page layouts are defined by default: empty, one_column, two_columns_left, two_columns_right and three_columns.
I would like to remove two_columns_left, two_columns_right for my layout, since the user can choose it in CMS and product design section, but it doesn't work.
How do I change an XML configuration file to accomplish this?
I found that I can remove it from the app/core/community/Mage/Page/etc/config.xml, but I would like to do this without change any core source, to be updateable.
I stumbled across this question looking for something similar and want to share my implementation. Maybe it is helpful for someone out there.
The following will remove the empty, 2_columns_right and 3_columns layouts from the list of available templates. Just change the remove_layouts directive in the config.xml below to remove whatever you want to remove.
I created a module (in fact the very first module I've ever built for magento) and placed the following in the file app/etc/modules/Labor_Templates.xml:
<?xml version="1.0"?>
<!--
/**
* This module changes the available templates. Only "1 column" and
* "2 column-left" will be available.
*/
-->
<config>
<modules>
<Labor_Templates>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Page />
</depends>
</Labor_Templates>
</modules>
</config>
Next, we need a config.xml found in /app/code/local/Labor/Templates/etc:
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Overrides the config to only allow "1 column" and "2 column left" layouts.
*/
-->
<config>
<modules>
<Labor_Templates>
<version>1.0.0</version>
</Labor_Templates>
</modules>
<global>
<models>
<template>
<class>Labor_Templates_Model</class>
</template>
<page>
<rewrite>
<config>Labor_Templates_Model_Config</config>
</rewrite>
</page>
</models>
<page>
<remove_layouts>
<layouts>empty,two_columns_right,three_columns</layouts>
</remove_layouts>
</page>
</global>
</config>
Notice, that I've added the remove_layouts directive. Finally we write our own Labor_Templates_Model_Config class:
<?php
/**
* Overrides the Overrides the core module Mage_Page_Model_Config in order to
* remove unused template layouts. This is done by handling remove_layout
* directives.
*/
class Labor_Templates_Model_Config extends Mage_Page_Model_Config {
const XML_PATH_PAGE_REMOVE_LAYOUTS = 'global/page/remove_layouts';
/**
* Initialize page layouts list
*
* #return Labor_Templates_Model_Config
*/
protected function _initPageLayouts()
{
parent::_initPageLayouts();
return $this->_removePageLayouts(self::XML_PATH_PAGE_REMOVE_LAYOUTS);
}
/**
* Removes page layouts found in the remove_layouts XML directive
*
* #return Labor_Templates_Model_Config
*/
protected function _removePageLayouts($xmlPath)
{
if (!Mage::getConfig()->getNode($xmlPath) || !is_array($this->_pageLayouts)) {
return $this;
}
foreach (explode(',', (string)Mage::getConfig()->getNode($xmlPath)->children()->layouts) as $toRemove) {
unset($this->_pageLayouts[$toRemove]);
}
return $this;
}
}
Works and tested with Magento 1.7.0.
Because the root layouts are parsed from config XML, and due to the way in which config XML is merged together, your simplest option (as you've surmised) is to edit app/core/community/Mage/Page/etc/config.xml.
If you are really concerned with not editing core files - always a legitimate & fun endeavor - you could create a module that can handle remove_layout directives, which you could add in your module's config under the same xpath. The class you would be rewriting is Mage_Page_Model_Config - see the _appendPageLayouts() and getPageLayouts() methods.

Add css from a block

I am building a custom magento module and i try to add a custom css file to my block. I wrote :
<?php
class Wise_InteractiveSlider_Block_Slider extends Mage_Core_Block_Template
{
protected function _prepareLayout()
{
$this->getLayout()->getBlock('head')->addCss('css/mycompany/mymodule/stylesheet.css');
return parent::_prepareLayout();
}
}
but it doesn't work, my css file is not loaded, any idea?
Thank you.
My alternative solution was to add this in my xml layout :
<default>
<reference name="head">
<action method="addCss"><stylesheet>css/interactiveslider.css</stylesheet></action>
</reference>
</default>
Thank you for your help
All the CSS & Images are normally available in the "skin" folder. It should be:-
"skin" folder
-> Package Name (like "base" or "default")
-> Theme Name (like "modern" or "mycompany")
-> "css" folder
-> "mymodule" folder
-> "stylesheet.css" file
So I suppose that you have been following this above-mentioned basic structure, which is considered as one of the best practices.
Coming back to your question, I suppose that you have mentioned the correct block class in your module's layout file "layout.xml". So the above code should be, according to the above folder structure:-
<?php
class Wise_InteractiveSlider_Block_Slider extends Mage_Core_Block_Template
{
protected function _prepareLayout()
{
$this->getLayout()->getBlock('head')->addCss('css/mymodule/stylesheet.css');
return parent::_prepareLayout();
}
}
Lastly, please make sure that you have uploaded your CSS file "stylesheet.css" in the correct folder.
Hope it helps.
You can only use the _prepareLayout() method if the block is defined in the layout XML. If you 'inline' the block inside a CMS page via the {{block type... method, the layout is already prepared by the time the block is rendered

Eclipse Contextual Help

Now can I register contextual help in an Eclipse WizardDialog/Editor.
1) I created a help_contexts.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<?NLS TYPE="org.eclipse.help.contexts"?>
<contexts>
<context id="my.plugin.help.general" >
<description>test</description>
<topic label="test" href="http://domain.com/help.html"/>
</context>
</contexts>
2) I referenced this file in my plugin.xml
<extension
point="org.eclipse.help.contexts">
<contexts file="help_contexts.xml" plugin="my.plugin.MainEditor">
</contexts>
</extension>
3) I added a line in my build.properties to include this file in the bin directory (bin.includes = help_contexts.xml, ... )
4) When running my GEF-based plugin, I see "No match found for "my.plugin.MainEditor"" under dynamic help.
I know I need to create something like this somewhere, but I don't know where to set this up for my WizardDialog or at least for my whole editor:
public void createPartControl(Composite parent) {
...
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
"my.plugin.help.general");
}
Note: This question originally contained two questions. I have removed the first (unanswered part) to be posted elsewhere.
Here is how you do it:
1) I created a help_contexts.xml file. Don't have periods in the context id. Don't include your plugin name in there.
<?xml version="1.0" encoding="UTF-8"?>
<?NLS TYPE="org.eclipse.help.contexts"?>
<contexts>
<context id="help_general" >
<description>test</description>
<topic label="test" href="http://domain.com/help.html"/>
</context>
</contexts>
2) I referenced this file in my plugin.xml Don't include the plugin-id if you are referencing your own plugin.
<extension
point="org.eclipse.help.contexts">
<contexts file="help_contexts.xml">
</contexts>
</extension>
3) I added a line in my build.properties to include this file in the bin directory (bin.includes = help_contexts.xml, ... ). Note your Bundle-SymbolicName in your Manifest.MF (also visible in your plugin.xml editor). Example: my.plugin
4) Set the context id in the WizardPage (credit goes to #VonC)
public class MyWizardPage extends WizardPage
public void createControl(Composite parent) {
PlatformUI.getWorkbench.getHelpSystem.setHelp(parent, "my.plugin.help_general");
}
}
For the main question, I am not sure about your setHelp second parameter. See this thread:
In the method call
PlatformUI.getWorkbench().getHelpSystem().setHelp()
second parameter is the contextID.
It should be prefixed with the pluginID like : "pluginID.contextID".
Now I was not sure where to find the plug-in ID for my plug-in.
So I used the value of this property : Bundle-Name Bundle-Symbolic-Name from MANIFEST.MF as the plug-in ID.
Now it works.
For the sidenote (help for WizardDialog), this thread might help (from David Kyle
and his blog "Eclipse RCP"):
We set the context id in our wizard page.
public class MyWizardPage extends WizardPage
public void createControl(Composite parent) {
PlatformUI.getWorkbench.getHelpSystem.setHelp(parent,
MyPluginActivator.ID + ".mycontexthelpid");
}
}
and we set help for the wizard dialog.
WizardDialog dialog = new WizardDialog(.....);
PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(),
"mycontexthelp.id");
We don't override performHelp().
As for the help context id. Define a context xml file in your plugin.
<?xml version="1.0" encoding="UTF-8"?>
<?NLS TYPE="org.eclipse.help.contexts"?>
<contexts>
<context id="mycontexthelpid" >
<description>My wizard help.</description>
<topic label="Wizard help" href="reference/wizard/help.xhtml"/>
</context>
</contexts>
in your plugin
<plugin>
<extension point="org.eclipse.help.contexts">
<contexts file="mywizard.xml" plugin="com.mypluginid"/>
</extension>
</plugin>
A common problem is messing up the plugin and context help ids. You can set
a couple of break points to see which context id is being requested.

Removing the About link from maven site

I'm using mvn site to generate my site's documentation. For the most part, I'm satisfied with the default site, but I'd like to remove the "About" link from the left hand menu bar and just have the default page be the "Project Information" page. Is there an easy way to do this?
Here only the 'About' report is still included. All other standard reports are removed.
<reporting>
<plugins>
<!-- Add the Maven project information reports -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.1.2</version>
<reportSets>
<reportSet>
<reports>
<report>index</report>
<!--
<report>dependencies</report>
<report>project-team</report>
<report>mailing-list</report>
<report>cim</report>
<report>issue-tracking</report>
<report>license</report>
<report>scm</report>
-->
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
You can either modify the source and comment it out or add a css selector for it, or you can include a JS library like jQuery and remove it when the page loads via something like:
$(function () {
// untested
$('#navcolumn h5:contains("Maven")').hide(); // hide the header
$('#navcolumn h5:contains("Maven") + ul ').hide(); // hide the ul
})();
I ended up not using that plugin at all and just used the maven-site-plugin. Maven 3 has a reportPlugins configuration section of the maven pom that lets you specified which reports you want to show up http://maven.apache.org/plugins/maven-site-plugin/maven-3.html
org.apache.maven.plugins
maven-site-plugin
3.0
org.codehaus.mojo
cobertura-maven-plugin
I also provided my own index.apt (in src/site/apt) file to customize the index page text.
I know this is an old question, but I've always found it quite annoying. The 'About' section is redundant, and more important, cause the 'Project Information' menu is expanded by default when you visit the site. Since I didn't found any solution on the web, I had to figure it out myself.
With the following workaround, the 'About' item under the 'Project Information' menu will completely disappear from the site. Just add this to the site.xml file:
...
<body>
<head>
<![CDATA[
<script type="text/javascript">
$(document).ready(function () {
var linkAbout = $('a').filter(function(index) { return $(this).text() === "About"; });
var projectInformationMenu = $('a').filter(function(index) { return $(this).text() === "Project Information"; });
linkAbout.hide();
if (!projectInformationMenu.parent().hasClass('active')) {
projectInformationMenu.parent().children('ul').hide();
projectInformationMenu.children('span').removeClass('icon-chevron-down').addClass('icon-chevron-right');
}
});
</script>
]]>
</head>
...
</body>

Resources