diff --git a/menuitemtypes/Page.php b/menuitemtypes/Page.php
index 851bf06..11dc37d 100644
--- a/menuitemtypes/Page.php
+++ b/menuitemtypes/Page.php
@@ -27,12 +27,23 @@ public function extendItemForm(Form $form)
'tab' => 'Item',
],
'data[params]' => [
- 'label' => 'Slug Parameters',
- 'comment' => 'If a slug uses a parameter such as :slug, enter a value for it here. Enter valid JSON - for example {"slug":"my-page-slug"}',
+ 'label' => 'Slug Parameters / String parameters',
+ 'comment' => 'If a slug uses a parameter such as :slug, enter a value for it here. Enter valid JSON - for example {"slug":"my-page-slug"}. If not valid JSON will be provided - the parameters string will be added as suffix to the url',
'type' => 'text',
'options' => DropDownHelper::instance()->pages(),
'tab' => 'Item',
],
+ 'is_absolute' => [
+ 'label'=> 'Absolute/Relative?',
+ 'span'=> 'left',
+ 'type'=> 'dropdown',
+ 'comment'=> 'How to build the link, to make it relative or absolute',
+ 'options'=> [
+ 0 => 'Relative',
+ 1 => 'Absolute'
+ ],
+ 'tab'=> 'Attributes'
+ ]
], 'primary');
}
@@ -66,9 +77,10 @@ public function extendItemModel(MenuItem $item)
public function getUrl(MenuItem $item)
{
$params = [];
+ $absolute = ($item->attributes['is_absolute']*1 == 1)?true:false;
if ( !empty($item->data['params']) )
$params = (array)json_decode($item->data['params']);
- return Pg::url(Pg::find($item->master_object_id)->fileName, $params);
+ return Pg::url(Pg::find($item->master_object_id)->fileName, $params, $absolute);
}
-}
\ No newline at end of file
+}
diff --git a/models/Menuitem.php b/models/Menuitem.php
index cc11e82..2de8013 100644
--- a/models/Menuitem.php
+++ b/models/Menuitem.php
@@ -31,7 +31,7 @@ class Menuitem extends Model
/**
* @var array Fillable fields
*/
- protected $fillable = ['enabled', 'label', 'title_attrib', 'id_attrib', 'class_attrib', 'target_attrib', 'selected_item_id', 'url', 'data', 'master_object_class', 'master_object_id', 'parent_id'];
+ protected $fillable = ['enabled', 'label', 'title_attrib', 'id_attrib', 'class_attrib', 'target_attrib','is_absolute', 'selected_item_id', 'url', 'data', 'master_object_class', 'master_object_id', 'parent_id'];
public $belongsTo = [
'menu' => ['Flynsarmy\Menu\Models\Menu'],
diff --git a/partials/_menuitem.php b/partials/_menuitem.php
index 8bfa78b..a651ff4 100644
--- a/partials/_menuitem.php
+++ b/partials/_menuitem.php
@@ -1,13 +1,19 @@
data['params'])){
+ $p = json_decode($this->data['params'],true);
+ $urlParams = ($p === null)?$this->data['params']:'?'.http_build_query($p);
+ }
+
$output = sprintf($settings['before_item'], $this->id, $this->id_attrib, $this->getClassAttrib($settings, $depth), $this->title_attrib);
$output .= $url ?
- sprintf($settings['before_url_item_label'], $url, $this->id, $this->id_attrib, $this->getClassAttrib($settings, $depth), $depth, $this->title_attrib, $this->target_attrib) : //
+ sprintf($settings['before_url_item_label'], $url.$urlParams, $this->id, $this->id_attrib, $this->getClassAttrib($settings, $depth), $depth, $this->title_attrib, $this->target_attrib) : //
sprintf($settings['before_nourl_item_label'], $this->id, $this->id_attrib, $this->getClassAttrib($settings, $depth), $depth, $this->title_attrib); //
$output .= htmlspecialchars($this->label);
$output .= $url ?
- sprintf($settings['after_url_item_label'], $url, $this->id, $this->id_attrib, $this->getClassAttrib($settings, $depth), $depth, $this->title_attrib) : //
+ sprintf($settings['after_url_item_label'], $url.$urlParams, $this->id, $this->id_attrib, $this->getClassAttrib($settings, $depth), $depth, $this->title_attrib) : //
sprintf($settings['after_nourl_item_label'], $this->id, $this->id_attrib, $this->getClassAttrib($settings, $depth), $depth, $this->title_attrib); //
if ( $child_count || $settings['always_show_before_after_children'] )
diff --git a/updates/add_menuitem_is_absolute_field.php b/updates/add_menuitem_is_absolute_field.php
new file mode 100644
index 0000000..9f9a2cc
--- /dev/null
+++ b/updates/add_menuitem_is_absolute_field.php
@@ -0,0 +1,25 @@
+string('is_absolute')->default(0);
+ });
+ }
+
+ public function down()
+ {
+ Schema::table('flynsarmy_menu_menuitems', function($table)
+ {
+ $table->dropColumn('is_absolute');
+ });
+ }
+
+}
diff --git a/updates/version.yaml b/updates/version.yaml
index 01e383e..e96690c 100644
--- a/updates/version.yaml
+++ b/updates/version.yaml
@@ -15,4 +15,7 @@
1.0.10: Remove comma in item links
1.0.11:
- Add slug parameters option for Page items
- - add_menuitem_data_field.php
\ No newline at end of file
+ - add_menuitem_data_field.php
+1.0.12:
+ - Add Absolute/Relative switcher for menu link
+ - add_menuitem_is_absolute_field.php
\ No newline at end of file