Skip to main content

Microsoft

Sitecore Media Framework – Import Buttons Not Displaying

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:

  1. In the Content Editor, switch to the master database and navigate to /sitecore/System/Settings/Rules/Command Rules/Rules.
  2. Create a new item using the following settings:
    • Name: MyCompany Import Content
    • Template: /templates/System/Rules/Command State Rule
  3. Set the Name field to the proper name of your command, e.g., MyCompany Import Content.
  4. Set Command to the name of the command you put on your Import button in the Core database and patched into the commands 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.
  5. Click Edit Rule.
  6. Add the where the account template is specific template condition and select the Account Template you created in Section 2.1.2 of the Media Framework documentation as the specific template.
  7. Add the set command state to the specific command state and select Enabled for the specific command state.
  8. Click OK and save the rule.
  9. 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 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!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Corey Smith, Sitecore MVP & Lead Technical Consultant

I'm a Sitecore MVP and Lead Technical Consultant at Perficient focusing on Sitecore and custom .NET development.

More from this Author

Categories
Follow Us
TwitterLinkedinFacebookYoutubeInstagram