From f26815b5ccfb0cb3f7f20045d94d5cc8ae2d5f9e Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 11 Sep 2014 12:52:45 +0800 Subject: [PATCH 1/4] Update Page.php --- menuitemtypes/Page.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/menuitemtypes/Page.php b/menuitemtypes/Page.php index 851bf06..04a03ca 100644 --- a/menuitemtypes/Page.php +++ b/menuitemtypes/Page.php @@ -66,9 +66,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 +} From 111417aec64277561031c22b4dfb95322e2f42c9 Mon Sep 17 00:00:00 2001 From: anton romanov Date: Thu, 11 Sep 2014 14:15:25 +0800 Subject: [PATCH 2/4] additional updates for previous commit. Both commit adding the ability to switch Relative or Absolute path for url builder --- menuitemtypes/Page.php | 2 +- models/Menuitem.php | 2 +- models/menuitem/fields.yaml | 10 +++++++++ updates/add_menuitem_is_absolute_field.php | 25 ++++++++++++++++++++++ updates/version.yaml | 5 ++++- 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 updates/add_menuitem_is_absolute_field.php diff --git a/menuitemtypes/Page.php b/menuitemtypes/Page.php index 04a03ca..727b379 100644 --- a/menuitemtypes/Page.php +++ b/menuitemtypes/Page.php @@ -70,6 +70,6 @@ public function getUrl(MenuItem $item) if ( !empty($item->data['params']) ) $params = (array)json_decode($item->data['params']); - return Pg::url(Pg::find($item->master_object_id)->fileName, $params, $absolute)); + return Pg::url(Pg::find($item->master_object_id)->fileName, $params, $absolute); } } 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/models/menuitem/fields.yaml b/models/menuitem/fields.yaml index 5a78c9c..0f0f444 100644 --- a/models/menuitem/fields.yaml +++ b/models/menuitem/fields.yaml @@ -42,6 +42,16 @@ tabs: _top: Top tab: Attributes + is_absolute: + label: Is absolute path + span: left + type: dropdown + comment: How to build the like, to make it relative or absolute + options: + 0: Relative + 1: Absolute + tab: Attributes + title_attrib: label: Title Attribute span: right 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 From ea7a2608a2754714e1d362d2de53d8b442b4ad6f Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 12 Sep 2014 11:03:24 +0800 Subject: [PATCH 3/4] [fixed] Absolute/Relative switcher should be available only for Pages --- menuitemtypes/Page.php | 11 +++++++++++ models/menuitem/fields.yaml | 10 ---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/menuitemtypes/Page.php b/menuitemtypes/Page.php index 727b379..d61707a 100644 --- a/menuitemtypes/Page.php +++ b/menuitemtypes/Page.php @@ -33,6 +33,17 @@ public function extendItemForm(Form $form) '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'); } diff --git a/models/menuitem/fields.yaml b/models/menuitem/fields.yaml index 0f0f444..5a78c9c 100644 --- a/models/menuitem/fields.yaml +++ b/models/menuitem/fields.yaml @@ -42,16 +42,6 @@ tabs: _top: Top tab: Attributes - is_absolute: - label: Is absolute path - span: left - type: dropdown - comment: How to build the like, to make it relative or absolute - options: - 0: Relative - 1: Absolute - tab: Attributes - title_attrib: label: Title Attribute span: right From 9d36cdda58e37ae59f1bf9bce66bb5d1ccab5e16 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 12 Sep 2014 11:06:31 +0800 Subject: [PATCH 4/4] [Fixed] Slug parameters should be applied to the url, if exist. [Added] If Slug parameters is a not valid JSON - append parameters string as is to the url --- menuitemtypes/Page.php | 4 ++-- partials/_menuitem.php | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/menuitemtypes/Page.php b/menuitemtypes/Page.php index d61707a..11dc37d 100644 --- a/menuitemtypes/Page.php +++ b/menuitemtypes/Page.php @@ -27,8 +27,8 @@ 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', 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'] )