This repository has been archived by the owner on Aug 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from systemseed/mainmenu
[#155932196] Manage main menu.
- Loading branch information
Showing
11 changed files
with
192 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
backend-gifts/web/modules/falcon/falcon_gifts_api/falcon_gifts_api.services.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
services: | ||
serializer.normalizer.menu_link_content.falcon_gifts_api: | ||
class: Drupal\falcon_gifts_api\Normalizer\MenuLinkContentEntityNormalizer | ||
arguments: ['@jsonapi.link_manager', '@jsonapi.resource_type.repository', '@entity_type.manager'] | ||
tags: | ||
- { name: normalizer, priority: 22 } |
41 changes: 41 additions & 0 deletions
41
...ts/web/modules/falcon/falcon_gifts_api/src/Normalizer/MenuLinkContentEntityNormalizer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Drupal\falcon_gifts_api\Normalizer; | ||
|
||
use Drupal\jsonapi\Normalizer\ContentEntityNormalizer; | ||
use Drupal\jsonapi\ResourceType\ResourceType; | ||
use Drupal\menu_link_content\MenuLinkContentInterface; | ||
|
||
class MenuLinkContentEntityNormalizer extends ContentEntityNormalizer { | ||
|
||
/** | ||
* The interface or class that this Normalizer supports. | ||
* | ||
* @var string | ||
*/ | ||
protected $supportedInterfaceOrClass = MenuLinkContentInterface::class; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getFields($entity, $bundle, ResourceType $resource_type) { | ||
/** @var \Drupal\menu_link_content\MenuLinkContentInterface $entity */ | ||
if ($bundle != 'menu_link_content') { | ||
return parent::getFields($entity, $bundle, $resource_type); | ||
} | ||
|
||
// Check access to node if it is a link to node entity. | ||
$url_object = $entity->getUrlObject(); | ||
$url = $url_object->toString(); | ||
if ($url_object->isRouted() && ($params = $url_object->getRouteParameters()) && isset($params['node'])) { | ||
$node = $this->entityTypeManager->getStorage('node')->load($params['node']); | ||
if (!$node->access('view')) { | ||
$url = null; | ||
} | ||
} | ||
|
||
$entity->set('url', $url); | ||
return parent::getFields($entity, $bundle, $resource_type); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import request from 'superagent'; | ||
import jsonapify from 'superagent-jsonapify'; | ||
import config from '../config'; | ||
|
||
jsonapify(request); | ||
|
||
export function loadAll() { | ||
return { | ||
type: 'GET_MENU', | ||
payload: request | ||
.get(`${config.backend}/v1/gifts/jsonapi/menu_link_content/menu_link_content`) | ||
.query({ | ||
'fields[menu_link_content--menu_link_content]': 'uuid,title,url', | ||
'filter[menu_name][condition][path]': 'menu_name', | ||
'filter[menu_name][condition][value]': 'main', | ||
'filter[enabled][condition][path]': 'enabled', | ||
'filter[enabled][condition][value]': 1, | ||
'sort': 'weight' | ||
}) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,66 @@ | ||
import React from 'react'; | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { NavLink } from 'react-router-dom'; | ||
import * as menuActions from '../../actions/menu'; | ||
|
||
const MainMenu = ({ isMenuCollapsed, onMenuClick, location }) => ( | ||
<nav className={`main-navigation text-center ${isMenuCollapsed ? '' : 'open'}`}> | ||
<ul className="menu"> | ||
<li><NavLink to="/" exact onClick={onMenuClick} location={location}>Browse Gifts</NavLink></li> | ||
<li><NavLink to="/corporate" exact onClick={onMenuClick} location={location}>Corporate Gifts</NavLink></li> | ||
<li><NavLink to="/how-gifts-work" exact onClick={onMenuClick} location={location}>How Gifts Work</NavLink></li> | ||
<li><NavLink to="/faq" exact onClick={onMenuClick} location={location}>FAQs</NavLink></li> | ||
<li><NavLink to="/contact" exact onClick={onMenuClick} location={location}>Contact</NavLink></li> | ||
</ul> | ||
</nav> | ||
); | ||
class MainMenu extends Component { | ||
|
||
componentWillMount() { | ||
// Load list of pages is they haven't been loaded yet. | ||
const { menu, loadMenu, done } = this.props; | ||
if (!menu.list.length) { | ||
loadMenu().then(done, done); | ||
} | ||
} | ||
|
||
render = () => { | ||
const { isMenuCollapsed, onMenuClick, location, menu } = this.props; | ||
|
||
return (<nav className={`main-navigation text-center ${isMenuCollapsed ? '' : 'open'}`}> | ||
<ul className="menu"> | ||
{menu.list.map((item) => { | ||
if (!item.url) { | ||
return ''; | ||
} | ||
return (<li key={item.uuid}> | ||
<NavLink to={item.url} exact onClick={onMenuClick} location={location}>{item.title}</NavLink> | ||
</li>); | ||
})} | ||
</ul> | ||
</nav>); | ||
} | ||
|
||
} | ||
|
||
MainMenu.propTypes = { | ||
isMenuCollapsed: React.PropTypes.bool.isRequired, | ||
onMenuClick: React.PropTypes.func.isRequired, | ||
location: React.PropTypes.object.isRequired, | ||
loadMenu: React.PropTypes.func, | ||
done: React.PropTypes.func, | ||
menu: React.PropTypes.shape({ | ||
isPending: React.PropTypes.bool, | ||
isFulfilled: React.PropTypes.bool, | ||
isError: React.PropTypes.bool, | ||
list: React.PropTypes.arrayOf( | ||
React.PropTypes.shape({ | ||
uuid: React.PropTypes.string, | ||
title: React.PropTypes.string, | ||
url: React.PropTypes.string | ||
}) | ||
) | ||
}) | ||
}; | ||
|
||
// Pass location prop to NavLink explicitly. | ||
// See https://github.com/ReactTraining/react-router/issues/4638 | ||
const mapStateToProps = state => ({ | ||
location: state.router.location | ||
// Pass location prop to NavLink explicitly. | ||
// See https://github.com/ReactTraining/react-router/issues/4638 | ||
location: state.router.location, | ||
menu: state.menu | ||
}); | ||
|
||
export default connect(mapStateToProps)(MainMenu); | ||
const mapDispatchToProps = { | ||
loadMenu: menuActions.loadAll, | ||
}; | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(MainMenu); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export const menu = (state = { | ||
isPending: false, | ||
isFulfilled: false, | ||
isError: false, | ||
list: [] | ||
}, action) => { | ||
switch (action.type) { | ||
|
||
case 'GET_MENU_PENDING': | ||
return { | ||
...state, | ||
isPending: true, | ||
}; | ||
|
||
case 'GET_MENU_FULFILLED': { | ||
const data = action.payload.body.data; | ||
const list = []; | ||
|
||
data.forEach((item) => { | ||
list.push(item.attributes); | ||
}); | ||
|
||
return { | ||
...state, | ||
isPending: false, | ||
isFulfilled: true, | ||
list | ||
}; | ||
} | ||
|
||
case 'GET_MENU_REJECTED': | ||
return { | ||
...state, | ||
isPending: false, | ||
isError: true, | ||
}; | ||
|
||
default: | ||
return state; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters