I developed a custom connector for the Sitecore Media Framework for a client to import media from their Digital Asset Management system into Sitecore through the Content Editor. Sitecore's documentation for developing a custom connector lays out the process for developing a connector very well, but it leaves out a key step when creating the Import
button.
If you're having issues getting the Import
button to appear for your Sitecore Media Framework connector, I've got you covered in this post.
3.3.4 Create Command Rule
Consider this a supplement to Section 3.3 - Import Command of the Media Framework documentation. I'm going to assume that you've gone through all the steps in this section to create your Import
button in the Core
database and patch the command into the commands
section of Sitecore config.
Now create a command rule for your command:
- In the Content Editor, switch to the
master
database and navigate to/sitecore/System/Settings/Rules/Command Rules/Rules
. - Create a new item using the following settings:
Name
: MyCompany Import ContentTemplate
:/templates/System/Rules/Command State Rule
- Set the
Name
field to the proper name of your command, e.g., MyCompany Import Content. - Set
Command
to the name of the command you put on yourImport
button in theCore
database and patched into thecommands
section of Sitecore config, e.g.,mediaFramework:ManualImport:MyCompany
. Command names are case sensitive, so make sure you've got the casing consistent in all three of these places. - Click
Edit Rule
. - Add the
where the account template is specific template
condition and select theAccount Template
you created in Section 2.1.2 of the Media Framework documentation as thespecific template
. - Add the
set command state to the specific command state
and selectEnabled
forthe specific command state
. - Click
OK
and save the rule. - Don't forget to save the rule to your source control repository through Unicorn or Team Development for Sitecore.
Your rule should now appear in the Media Framework
section of the ribbon when you click on an item created with your Account Template
, or one of its descendants, in the Content Tree.
If your rule still doesn't show up, double check the casing of your command, e.g., mediaFramework:ManualImport:MyCompany
, on the button in the core
database, in the commands
section of your patch file, and the Command State Rule
you created above. The casing must match across all of these.
What's Going On?
The command you patched into Sitecore, e.g., mediaFramework:ManualImport:MyCompany
, is driven by the Media Framework command class Sitecore.MediaFramework.Commands.ImportContent
in the Sitecore.MediaFramework
assembly. This command class derives from another command class, Sitecore.Integration.Common.Commands.RuleBasedCommand
in the Sitecore.Integration
assembly installed by the Media Framework.
This class is pretty cool--its command state is driven entirely by a rule found under /sitecore/system/Settings/Rules/Command Rules/Rules
with the corresponding command set in its Command
field. The default state of the RuleBasedCommand
is Disabled
, which is why the button does not appear in the UI when the rule is not present.
If, for whatever reason, you didn't want to mess around with the rules, you could easily extend the ImportContent
class to change this behavior:
namespace SitecoreDemo
{
public class AlwaysEnabledImportContent : ImportContent
{
protected override CommandState DefaultCommandState => CommandState.Enabled;
}
}
Update your patch file to use this type
instead:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<commands>
<command name="mediaFramework:ManualImport:MyCompany"
type="SitecoreDemo.AlwaysEnabledImportContent, SitecoreDemo" />
</commands>
</sitecore>
</configuration>
Now your button will appear when you don't have a rule setup.
Has this helped you out? Let me know in the comments. Cheers!