Orchard MediaPickerField to MediaLibraryPickerField - orchardcms

I am currently trying to update a site from Orchard 1.6 to 1.8.
Ran into some issues at the Media -> Media Library step.
We have this in our Migrations.cs
SchemaBuilder.CreateTable(typeof(CarouselRecord).Name, table => table
.ContentPartRecord()
.Column<string>("Interval", column => column.WithDefault(""))
.Column<string>("MinHeight", column => column.WithDefault(""))
);
ContentDefinitionManager.AlterPartDefinition(
typeof(CarouselPart).Name, cfg => cfg
.WithField("CarouselImage1", fieldBuilder => fieldBuilder.OfType("MediaPickerField").WithDisplayName("Img1"))
.WithField("CarouselImage2", fieldBuilder => fieldBuilder.OfType("MediaPickerField").WithDisplayName("Img2"))
.WithField("CarouselImage3", fieldBuilder => fieldBuilder.OfType("MediaPickerField").WithDisplayName("Img3"))
.WithField("CarouselImage4", fieldBuilder => fieldBuilder.OfType("MediaPickerField").WithDisplayName("Img4"))
.Attachable()
);
ContentDefinitionManager.AlterTypeDefinition("CarouselWidget", cfg => cfg
.WithPart(typeof(CarouselPart).Name)
.WithPart("WidgetPart")
.WithPart(typeof(CommonPart).Name)
.WithSetting("Stereotype", "Widget")
);
After disabling the Media module and Enabling the Media Library Module (and migrating the Media Files and Media picker fields), this stopped working completelty, crashing at this line in the .cshtml:
<div class="item"><img src="#(Href(Model.ContentPart.CarouselImage2.Url))" alt="" /></div>
First i tried updating the template to use MediaLibraryPickerFields instead, but no luck.
Turns out, when i go to admin -> widgets -> edit widget, the media fields for the widget is gone.
Did i do something wrong in the updating process, or do i have to write new updates in Migrations.cs to remove the MediaPickerFields and add MediaLibraryPickerFields instead?

3 Months and no answer, thought i would close this.
What i ended up doing was removing the MediaPickerFields
ContentDefinitionManager.AlterPartDefinition(
typeof(CarouselPart).Name, cfg => cfg
.RemoveField("CarouselImage1")
.RemoveField("CarouselImage2")
.RemoveField("CarouselImage3")
.RemoveField("CarouselImage4")
.Attachable()
);
and then adding a MediaLibraryPickerField instead
ContentDefinitionManager.AlterPartDefinition(
typeof(CarouselPart).Name, cfg => cfg
.WithField("CarouselImages", fieldBuilder => fieldBuilder.OfType("MediaLibraryPickerField").WithDisplayName("Images").WithSetting("MediaLibraryPickerFieldSettings.Multiple", "true"))
.Attachable()
);
Not optimal due to the loss of data, but it was not a big issue in this case.

Related

WPBakery multiple WYSIWYG editors

so I am building fairly complex WP site based on WPBakery editor with tons of custom components.
I just found out that some of them need to have multiple textarea_html (WYSIWYG) fields and judging by documentation only one of those fields is allowed per component:
Text area with default WordPress WYSIWYG Editor. Important: only one html textarea is permitted per shortcode and it should have “content” as a param_name
They are defined like this:
array(
'type' => 'textarea_html',
'heading' => __( 'This is WYSIWYG editor', 'text-domain' ),
'param_name' => 'content',
'value' => __( '', 'text-domain' )
),
Adding more with the same type (textarea_html) just converts them (of course, per documentation) to basic textarea field like this:
array(
'type' => 'textarea',
'heading' => __( 'This is basic textarea block', 'text-domain' ),
'param_name' => 'someparamname',
'value' => __( '', 'text-domain' )
),
Any ideas how this could be done differently? Thought about using ACF but didnt had much luck there...

Add html to menu title in Drupal

I must have missed something. I can't figure out how to add some HTML into the title of the menu.
According to the menu api, I can't add options because I am using MENU_LOCAL_TASK, but then how? There is no say.
For example: if I try to make the title bold:
$items['whatever/tab2'] = array(
'title' => '<b>Tab 2</b>',
'type' => MENU_LOCAL_TASK,
);
This is not working.
You can use 'title callback' => 'example_title_callback',
Function to generate the title; defaults to t(). If you require only the raw string to be output, set this to FALSE.
You could use the Menu HTML module.

Display MediaLibraryPickerField when editting a part

I'm missing something here and can't for the life of me figure out what.
I've added a MediaLibraryPickerField to a part I created:
ContentDefinitionManager.AlterPartDefinition(typeof (FloorPlanPart).Name, cfg => cfg
.WithField("Photo", f => f
.OfType("MediaLibraryPickerField")
.WithDisplayName("Photo")
.WithSetting("MediaLibraryPickerFieldSettings.Required", "true")));
I can verify that this field has been added correctly to my part. This part belongs to a custom type:
ContentDefinitionManager.AlterTypeDefinition("FloorPlan", cfg => cfg
.WithPart(typeof(FloorPlanPart).Name)
.Creatable()
.Draftable(false));
I have my driver setup to return the following on an edit:
protected override DriverResult Editor(FloorPlanPart part, dynamic shapeHelper)
{
return ContentShape("Parts_FloorPlan_Edit",
() => shapeHelper.EditorTemplate(
TemplateName: "Parts/FloorPlan",
Model: part,
Prefix: Prefix));
}
my edit view looks like the following:
#using System.Web.Mvc.Html
#model Models.FloorPlanPart
<fieldset>
<legend>Floor Plan Fields</legend>
<div class="editor-label">#Html.LabelFor(x => x.FloorPlanName)</div>
<div class="editor-field">
#Html.EditorFor(x => x.FloorPlanName)
#Html.ValidationMessageFor(x => x.FloorPlanName)
</div>
</fieldset>
Some where along the line the Media picker is supposed to show up but never does when creating a new Floor Plan. All I get is just the fields in my part (FloorPlanName). How do I get the media picker to show? If I add the Media picker as a field on my content type it does show but shouldn't I be able to do it this way as well?
Rookie mistake, I thought I was using the latest version of Orchard 1.7.2 but was using 1.6.2.

Zend Layout in ZF2

How can we set default layout in zf2 if the layout folder is out side the module directory
You can set the layout anywhere you want it doesn't have to be in the modules directory.
just set it inside your modules config
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => '/anypath/you/want/view/layout/layout.phtml',
),
'template_path_stack' => array(
'/anypath/you/want/view',
),
),
As per the question posted the answer by #Andrew is correct .
When i notice the working of layout in zf2 i came to certain conclusion
Able to set the layout folder anyway in application environment
Only one layout is taken for all the modules , the layout taken is from the last module mentioned in application.config.php
For example
'modules' => array(
'Album',
'Testlist',
'Customer',
'Application',
'User',
),
Then the user layout will be taken .
if we have only one layout in the application this will be fine
To switching between layouts in the module came across
http://www.webtrafficexchange.com/zf2-configure-layout-each-module-edpmodulelayouts
which seems to be useful
The default layout is layout/layout configured in the view manager.

Drupal 6 textfield form element with ahah attribute

I have a form with a textfield element which when a user starts typing into I want to pre-populate a different element.
I've been using the #ahah attribute which works fine with the event property set to 'keyup' however I lose focus on the textfield element because the moment the 'keyup' event is fired the whole form is rebuilt due to ahah's behaviour.
I tried setting the event property to 'change' and that works nicely however in order for the 'change' event to fire I need to click away from the textfield - so from UI point of view I cannot expect users to click away from field just to get the results to display.
I'm not sure if it's possible to achieve what I want with AHAH which is fine but I'd like to stick with it if possible.
Happy to provide code if required and sorry if it's not clear, quite difficult to explain.
Thanks
Steve
The whole form shouldn't be re-rendered by the browser. That's precisely the idea AHAH, that you can update just part of a form. Make sure to set the "wrapper" attribute (of the #ahah attribute) to the ID (as in: the HTML attribute) of the DOM element that you want Drupal's JS functionality to update asynchronously.
For example:
<?php
function MYMODULE_some_ahah_enabled_form(&$form_state) {
$initial_markup = '<div>' . t('This content will be replaced') . '</div>';
$form['dynamic_thing'] = array(
'#type' => 'markup',
'#prefix' => '<div id="dynamic-thing">', // Set Drupal's AHAH wrapper to this ID
'#suffix' => '</div>',
'#value' => $initial_markup,
);
$form['field_which_will_trigger_ahah_behavior'] = array(
'#type' => 'textfield',
'#ahah' => array(
'path' => 'MYMODULE/path/to/ahah/callback',
'wrapper' => 'dynamic-thing',
'event' => 'keyup',
),
'#default_value' => 'Change me',
);
return $form;
}
/**
* Your menu callback (which is declared in your hook_menu()) which returns only the HTML that will replace the existing markup in $form['dynamic_thing'].
*/
function MYMODULE_ahah_callback() {
$output = '<div>New content for the dynamic thing</div>';
drupal_json(array('status' => TRUE, 'data' => $output));
exit();
}
Your "field_which_will_trigger_ahah_behavior" DOM element in the browser shouldn't lose focus, or be re-rendered in any way, unless there's something else causing some bug.

Resources