Skip to:
Content

BuddyPress.org

Ticket #8518: 8518.patch

File 8518.patch, 24.7 KB (added by imath, 4 years ago)
  • Gruntfile.js

    diff --git Gruntfile.js Gruntfile.js
    index 8841c2358..16635088d 100644
    module.exports = function( grunt ) { 
    3333                        '!bp-templates/bp-legacy/css/twenty*.css',
    3434                        '!bp-templates/bp-nouveau/css/buddypress.css',
    3535                        '!bp-templates/bp-nouveau/css/twenty*.css',
     36                        '!bp-templates/bp-nouveau/css/primary-nav.css',
    3637                        '!bp-core/admin/css/hello.css',
    3738                        '!bp-members/css/blocks/member.css',
    3839                        '!bp-groups/css/blocks/group.css',
    module.exports = function( grunt ) { 
    119120                                expand: true,
    120121                                ext: '.css',
    121122                                flatten: true,
    122                                 src: ['bp-templates/bp-nouveau/sass/buddypress.scss', 'bp-templates/bp-nouveau/sass/twenty*.scss'],
     123                                src: ['bp-templates/bp-nouveau/sass/buddypress.scss', 'bp-templates/bp-nouveau/sass/twenty*.scss', 'bp-templates/bp-nouveau/sass/primary-nav.scss'],
    123124                                dest: SOURCE_DIR + 'bp-templates/bp-nouveau/css/'
    124125                        },
    125126                        admin: {
  • src/bp-core/classes/class-bp-core.php

    diff --git src/bp-core/classes/class-bp-core.php src/bp-core/classes/class-bp-core.php
    index c8b1e924b..0a010c2a9 100644
    class BP_Core extends BP_Component { 
    295295                        array(
    296296                                'block_globals' => array(
    297297                                        'bp/login-form' => array(
    298                                                 'widget_classnames' => array ( 'widget_bp_core_login_widget', 'buddypress' ),
     298                                                'widget_classnames' => array( 'widget_bp_core_login_widget', 'buddypress' ),
    299299                                        )
    300300                                )
    301301                        )
  • new file src/bp-core/js/blocks/primary-nav.js

    diff --git src/bp-core/js/blocks/primary-nav.js src/bp-core/js/blocks/primary-nav.js
    new file mode 100644
    index 000000000..67b40d2d0
    - +  
     1// modules are defined as an array
     2// [ module function, map of requires ]
     3//
     4// map of requires is short require name -> numeric require
     5//
     6// anything defined in a previous bundle is accessed via the
     7// orig method which is the require for previous bundles
     8parcelRequire = (function (modules, cache, entry, globalName) {
     9  // Save the require from previous bundle to this closure if any
     10  var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
     11  var nodeRequire = typeof require === 'function' && require;
     12
     13  function newRequire(name, jumped) {
     14    if (!cache[name]) {
     15      if (!modules[name]) {
     16        // if we cannot find the module within our internal map or
     17        // cache jump to the current global require ie. the last bundle
     18        // that was added to the page.
     19        var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
     20        if (!jumped && currentRequire) {
     21          return currentRequire(name, true);
     22        }
     23
     24        // If there are other bundles on this page the require from the
     25        // previous one is saved to 'previousRequire'. Repeat this as
     26        // many times as there are bundles until the module is found or
     27        // we exhaust the require chain.
     28        if (previousRequire) {
     29          return previousRequire(name, true);
     30        }
     31
     32        // Try the node require function if it exists.
     33        if (nodeRequire && typeof name === 'string') {
     34          return nodeRequire(name);
     35        }
     36
     37        var err = new Error('Cannot find module \'' + name + '\'');
     38        err.code = 'MODULE_NOT_FOUND';
     39        throw err;
     40      }
     41
     42      localRequire.resolve = resolve;
     43      localRequire.cache = {};
     44
     45      var module = cache[name] = new newRequire.Module(name);
     46
     47      modules[name][0].call(module.exports, localRequire, module, module.exports, this);
     48    }
     49
     50    return cache[name].exports;
     51
     52    function localRequire(x){
     53      return newRequire(localRequire.resolve(x));
     54    }
     55
     56    function resolve(x){
     57      return modules[name][1][x] || x;
     58    }
     59  }
     60
     61  function Module(moduleName) {
     62    this.id = moduleName;
     63    this.bundle = newRequire;
     64    this.exports = {};
     65  }
     66
     67  newRequire.isParcelRequire = true;
     68  newRequire.Module = Module;
     69  newRequire.modules = modules;
     70  newRequire.cache = cache;
     71  newRequire.parent = previousRequire;
     72  newRequire.register = function (id, exports) {
     73    modules[id] = [function (require, module) {
     74      module.exports = exports;
     75    }, {}];
     76  };
     77
     78  var error;
     79  for (var i = 0; i < entry.length; i++) {
     80    try {
     81      newRequire(entry[i]);
     82    } catch (e) {
     83      // Save first error but execute all entries
     84      if (!error) {
     85        error = e;
     86      }
     87    }
     88  }
     89
     90  if (entry.length) {
     91    // Expose entry point to Node, AMD or browser globals
     92    // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
     93    var mainExports = newRequire(entry[entry.length - 1]);
     94
     95    // CommonJS
     96    if (typeof exports === "object" && typeof module !== "undefined") {
     97      module.exports = mainExports;
     98
     99    // RequireJS
     100    } else if (typeof define === "function" && define.amd) {
     101     define(function () {
     102       return mainExports;
     103     });
     104
     105    // <script>
     106    } else if (globalName) {
     107      this[globalName] = mainExports;
     108    }
     109  }
     110
     111  // Override the current require with this new one
     112  parcelRequire = newRequire;
     113
     114  if (error) {
     115    // throw error from earlier, _after updating parcelRequire_
     116    throw error;
     117  }
     118
     119  return newRequire;
     120})({"Sw79":[function(require,module,exports) {
     121"use strict";
     122
     123Object.defineProperty(exports, "__esModule", {
     124  value: true
     125});
     126exports.default = void 0;
     127
     128/**
     129 * WordPress dependencies.
     130 */
     131var _wp = wp,
     132    InspectorControls = _wp.blockEditor.InspectorControls,
     133    _wp$components = _wp.components,
     134    Disabled = _wp$components.Disabled,
     135    Notice = _wp$components.Notice,
     136    PanelBody = _wp$components.PanelBody,
     137    ToggleControl = _wp$components.ToggleControl,
     138    _wp$element = _wp.element,
     139    Fragment = _wp$element.Fragment,
     140    createElement = _wp$element.createElement,
     141    __ = _wp.i18n.__;
     142/**
     143 * BuddyPress dependencies.
     144 */
     145
     146var _bp = bp,
     147    ServerSideRender = _bp.blockComponents.ServerSideRender,
     148    getCurrentWidgetsSidebar = _bp.blockData.getCurrentWidgetsSidebar;
     149
     150var editPrimaryNavBlock = function editPrimaryNavBlock(_ref) {
     151  var attributes = _ref.attributes,
     152      setAttributes = _ref.setAttributes,
     153      clientId = _ref.clientId;
     154  var displayTitle = attributes.displayTitle;
     155  var currentSidebar = getCurrentWidgetsSidebar(clientId);
     156  var disabledSidebars = ['sidebar-buddypress-members', 'sidebar-buddypress-groups'];
     157
     158  if (currentSidebar && currentSidebar.id && -1 !== disabledSidebars.indexOf(currentSidebar.id)) {
     159    return createElement(Notice, {
     160      status: "error",
     161      isDismissible: false
     162    }, createElement("p", null, __('The BuddyPress Primary Navigation block shouldn\'t be used into this widget area. Please remove it.', 'buddypress')));
     163  }
     164
     165  return createElement(Fragment, null, createElement(InspectorControls, null, createElement(PanelBody, {
     166    title: __('Settings', 'buddypress'),
     167    initialOpen: true
     168  }, createElement(ToggleControl, {
     169    label: __('Include navigation title', 'buddypress'),
     170    checked: !!displayTitle,
     171    onChange: function onChange() {
     172      setAttributes({
     173        displayTitle: !displayTitle
     174      });
     175    }
     176  }))), createElement(Disabled, null, createElement(ServerSideRender, {
     177    block: "bp/primary-nav",
     178    attributes: attributes
     179  })));
     180};
     181
     182var _default = editPrimaryNavBlock;
     183exports.default = _default;
     184},{}],"uKqo":[function(require,module,exports) {
     185"use strict";
     186
     187Object.defineProperty(exports, "__esModule", {
     188  value: true
     189});
     190exports.default = void 0;
     191
     192/**
     193 * WordPress dependencies.
     194 */
     195var _wp = wp,
     196    createBlock = _wp.blocks.createBlock;
     197/**
     198 * Transforms Legacy Widget to Primary Nav Block.
     199 *
     200 * @type {Object}
     201 */
     202
     203var transforms = {
     204  from: [{
     205    type: 'block',
     206    blocks: ['core/legacy-widget'],
     207    isMatch: function isMatch(_ref) {
     208      var idBase = _ref.idBase,
     209          instance = _ref.instance;
     210
     211      if (!(instance !== null && instance !== void 0 && instance.raw)) {
     212        return false;
     213      }
     214
     215      return idBase === 'bp_nouveau_sidebar_object_nav_widget';
     216    },
     217    transform: function transform(_ref2) {
     218      var instance = _ref2.instance;
     219      return createBlock('bp/primary-nav', {
     220        displayTitle: instance.raw.bp_nouveau_widget_title
     221      });
     222    }
     223  }]
     224};
     225var _default = transforms;
     226exports.default = _default;
     227},{}],"ygAa":[function(require,module,exports) {
     228"use strict";
     229
     230var _edit = _interopRequireDefault(require("./primary-nav/edit"));
     231
     232var _transforms = _interopRequireDefault(require("./primary-nav/transforms"));
     233
     234function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
     235
     236/**
     237 * WordPress dependencies.
     238 */
     239var _wp = wp,
     240    registerBlockType = _wp.blocks.registerBlockType,
     241    __ = _wp.i18n.__;
     242/**
     243 * Internal dependencies.
     244 */
     245
     246registerBlockType('bp/primary-nav', {
     247  title: __('Primary navigation', 'buddypress'),
     248  description: __('Displays BuddyPress primary nav in the sidebar of your site. Make sure to use it as the first widget of the sidebar and only once.', 'buddypress'),
     249  icon: {
     250    background: '#fff',
     251    foreground: '#d84800',
     252    src: 'buddicons-community'
     253  },
     254  category: 'buddypress',
     255  attributes: {
     256    displayTitle: {
     257      type: 'boolean',
     258      default: true
     259    }
     260  },
     261  edit: _edit.default,
     262  transforms: _transforms.default
     263});
     264},{"./primary-nav/edit":"Sw79","./primary-nav/transforms":"uKqo"}]},{},["ygAa"], null)
     265 No newline at end of file
  • new file src/bp-templates/bp-nouveau/css/primary-nav-rtl.css

    diff --git src/bp-templates/bp-nouveau/css/primary-nav-rtl.css src/bp-templates/bp-nouveau/css/primary-nav-rtl.css
    new file mode 100644
    index 000000000..8811471c2
    - +  
     1.buddypress_object_nav .bp-navs {
     2        background: transparent;
     3        clear: both;
     4        overflow: hidden;
     5}
     6
     7.buddypress_object_nav .bp-navs ul {
     8        margin: 0;
     9        padding: 0;
     10}
     11
     12.buddypress_object_nav .bp-navs ul li {
     13        list-style: none;
     14        margin: 0;
     15}
     16
     17.buddypress_object_nav .bp-navs ul li.last select {
     18        max-width: 185px;
     19}
     20
     21.buddypress_object_nav .bp-navs ul li a,
     22.buddypress_object_nav .bp-navs ul li span {
     23        border: 0;
     24        display: block;
     25        padding: 5px 10px;
     26        text-decoration: none;
     27}
     28
     29.buddypress_object_nav .bp-navs ul li .count {
     30        background: #eaeaea;
     31        border: 1px solid #ccc;
     32        border-radius: 50%;
     33        color: #555;
     34        display: inline-block;
     35        font-size: 12px;
     36        margin-right: 2px;
     37        padding: 3px 6px;
     38        text-align: center;
     39        vertical-align: middle;
     40}
     41
     42.buddypress_object_nav .bp-navs ul li.selected a,
     43.buddypress_object_nav .bp-navs ul li.current a {
     44        color: #333;
     45        opacity: 1;
     46}
     47
     48.buddypress_object_nav .bp-navs ul li.selected a .count,
     49.buddypress_object_nav .bp-navs ul li.current a .count {
     50        background-color: #fff;
     51}
     52
     53.buddypress_object_nav .bp-navs ul li.dynamic a .count,
     54.buddypress_object_nav .bp-navs ul li.dynamic.selected a .count,
     55.buddypress_object_nav .bp-navs ul li.dynamic.current a .count {
     56        background-color: #5087e5;
     57        border: 0;
     58        color: #fafafa;
     59}
     60
     61.buddypress_object_nav .bp-navs ul li.dynamic a:hover .count {
     62        background-color: #5087e5;
     63        border: 0;
     64        color: #fff;
     65}
     66
     67.buddypress_object_nav .bp-navs ul li a .count:empty {
     68        display: none;
     69}
     70
     71.buddypress_object_nav .main-navs.dir-navs {
     72        margin-bottom: 20px;
     73}
     74
     75.buddypress_object_nav .bp-navs.group-create-links ul li:not(.current) {
     76        color: #767676;
     77}
     78
     79.buddypress_object_nav .bp-navs.group-create-links ul li:not(.current) a {
     80        color: #767676;
     81}
     82
     83.buddypress_object_nav .bp-navs.group-create-links ul li:not(.current) a:focus, .buddypress_object_nav .bp-navs.group-create-links ul li:not(.current) a:hover {
     84        background: none;
     85        color: #555;
     86}
     87
     88.buddypress_object_nav .bp-navs.group-create-links ul li:not(.current) a[disabled]:focus, .buddypress_object_nav .bp-navs.group-create-links ul li:not(.current) a[disabled]:hover {
     89        color: #767676;
     90}
     91
     92.buddypress_object_nav .bp-navs.group-create-links ul li.current a {
     93        text-align: center;
     94}
  • new file src/bp-templates/bp-nouveau/css/primary-nav.css

    diff --git src/bp-templates/bp-nouveau/css/primary-nav.css src/bp-templates/bp-nouveau/css/primary-nav.css
    new file mode 100644
    index 000000000..01f3e6c2d
    - +  
     1.buddypress_object_nav .bp-navs {
     2        background: transparent;
     3        clear: both;
     4        overflow: hidden;
     5}
     6
     7.buddypress_object_nav .bp-navs ul {
     8        margin: 0;
     9        padding: 0;
     10}
     11
     12.buddypress_object_nav .bp-navs ul li {
     13        list-style: none;
     14        margin: 0;
     15}
     16
     17.buddypress_object_nav .bp-navs ul li.last select {
     18        max-width: 185px;
     19}
     20
     21.buddypress_object_nav .bp-navs ul li a,
     22.buddypress_object_nav .bp-navs ul li span {
     23        border: 0;
     24        display: block;
     25        padding: 5px 10px;
     26        text-decoration: none;
     27}
     28
     29.buddypress_object_nav .bp-navs ul li .count {
     30        background: #eaeaea;
     31        border: 1px solid #ccc;
     32        border-radius: 50%;
     33        color: #555;
     34        display: inline-block;
     35        font-size: 12px;
     36        margin-left: 2px;
     37        padding: 3px 6px;
     38        text-align: center;
     39        vertical-align: middle;
     40}
     41
     42.buddypress_object_nav .bp-navs ul li.selected a,
     43.buddypress_object_nav .bp-navs ul li.current a {
     44        color: #333;
     45        opacity: 1;
     46}
     47
     48.buddypress_object_nav .bp-navs ul li.selected a .count,
     49.buddypress_object_nav .bp-navs ul li.current a .count {
     50        background-color: #fff;
     51}
     52
     53.buddypress_object_nav .bp-navs ul li.dynamic a .count,
     54.buddypress_object_nav .bp-navs ul li.dynamic.selected a .count,
     55.buddypress_object_nav .bp-navs ul li.dynamic.current a .count {
     56        background-color: #5087e5;
     57        border: 0;
     58        color: #fafafa;
     59}
     60
     61.buddypress_object_nav .bp-navs ul li.dynamic a:hover .count {
     62        background-color: #5087e5;
     63        border: 0;
     64        color: #fff;
     65}
     66
     67.buddypress_object_nav .bp-navs ul li a .count:empty {
     68        display: none;
     69}
     70
     71.buddypress_object_nav .main-navs.dir-navs {
     72        margin-bottom: 20px;
     73}
     74
     75.buddypress_object_nav .bp-navs.group-create-links ul li:not(.current) {
     76        color: #767676;
     77}
     78
     79.buddypress_object_nav .bp-navs.group-create-links ul li:not(.current) a {
     80        color: #767676;
     81}
     82
     83.buddypress_object_nav .bp-navs.group-create-links ul li:not(.current) a:focus, .buddypress_object_nav .bp-navs.group-create-links ul li:not(.current) a:hover {
     84        background: none;
     85        color: #555;
     86}
     87
     88.buddypress_object_nav .bp-navs.group-create-links ul li:not(.current) a[disabled]:focus, .buddypress_object_nav .bp-navs.group-create-links ul li:not(.current) a[disabled]:hover {
     89        color: #767676;
     90}
     91
     92.buddypress_object_nav .bp-navs.group-create-links ul li.current a {
     93        text-align: center;
     94}
  • src/bp-templates/bp-nouveau/includes/functions.php

    diff --git src/bp-templates/bp-nouveau/includes/functions.php src/bp-templates/bp-nouveau/includes/functions.php
    index 77c1f93ef..105a65bc2 100644
     
    33 * Common functions
    44 *
    55 * @since 3.0.0
    6  * @version 8.0.0
     6 * @version 9.0.0
    77 */
    88
    99// Exit if accessed directly.
    function bp_nouveau_get_component_slug( $component_id = '' ) { 
    14891489         */
    14901490        return apply_filters( 'bp_nouveau_get_component_slug', $slug, $component_id );
    14911491}
     1492
     1493/**
     1494 * Registers the 'bp/primary-nav' Widget Block.
     1495 *
     1496 * @since 9.0.0
     1497 *
     1498 * @param array $blocks The Core Blocks list.
     1499 * @return array The Core Blocks list.
     1500 */
     1501function bp_nouveau_register_primary_nav_widget_block( $blocks = array() ) {
     1502        $editor_style = bp_locate_template_asset( 'css/primary-nav.css' );
     1503
     1504        $blocks['bp/primary-nav'] = array(
     1505                'name'               => 'bp/primary-nav',
     1506                'editor_script'      => 'bp-primary-nav-block',
     1507                'editor_script_url'  => trailingslashit( buddypress()->plugin_url . 'bp-core' ) . 'js/blocks/primary-nav.js',
     1508                'editor_script_deps' => array(
     1509                        'wp-blocks',
     1510                        'wp-element',
     1511                        'wp-components',
     1512                        'wp-i18n',
     1513                        'wp-block-editor',
     1514                        'bp-block-data',
     1515                        'bp-block-components',
     1516                ),
     1517                'editor_style'       => 'bp-primary-nav-block',
     1518                'editor_style_url'   => $editor_style['uri'],
     1519                'attributes'         => array(
     1520                        'displayTitle' => array(
     1521                                'type'    => 'boolean',
     1522                                'default' => true,
     1523                        ),
     1524                ),
     1525                'render_callback'    => 'bp_nouveau_render_primary_nav_block',
     1526        );
     1527
     1528        return $blocks;
     1529}
     1530add_filter( 'bp_core_register_blocks', 'bp_nouveau_register_primary_nav_widget_block', 20, 1 );
     1531
     1532/**
     1533 * Registers the 'bp/primary-nav' Widget Block classnames.
     1534 *
     1535 * @since 9.0.0
     1536 *
     1537 * @param array $block_globals The list of global properties for Core blocks.
     1538 * @return array               The list of global properties for Core blocks.
     1539 */
     1540function bp_nouveau_register_core_block_globals( $block_globals = array() ) {
     1541        $block_globals['bp/primary-nav'] = array(
     1542                'widget_classnames' => array( 'widget_nav_menu', 'buddypress_object_nav', 'buddypress' ),
     1543        );
     1544
     1545        return $block_globals;
     1546}
     1547add_filter( 'bp_core_block_globals', 'bp_nouveau_register_core_block_globals', 10, 1 );
     1548
     1549/**
     1550 * Unregister the 'bp/primary-nav' Block from the post context.
     1551 *
     1552 * @since 9.0.0
     1553 */
     1554function bp_nouveau_unregister_blocks_for_post_context() {
     1555        unregister_block_type( 'bp/primary-nav' );
     1556}
     1557add_action( 'load-post.php', 'bp_nouveau_unregister_blocks_for_post_context' );
     1558add_action( 'load-post-new.php', 'bp_nouveau_unregister_blocks_for_post_context' );
     1559
     1560/**
     1561 * Callback function to render the BP Primary Nav Block.
     1562 *
     1563 * @since 9.0.0
     1564 *
     1565 * @param array $attributes The block attributes.
     1566 * @return string           HTML output.
     1567 */
     1568function bp_nouveau_render_primary_nav_block( $attributes = array() ) {
     1569        $widget_content = '';
     1570        $widget_title   = '';
     1571        $block_args     = bp_parse_args(
     1572                $attributes,
     1573                array(
     1574                        'displayTitle' => true,
     1575                ),
     1576                'widget_object_nav'
     1577        );
     1578
     1579        // Previewing the Block inside the editor.
     1580        if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
     1581                $widget_title = bp_get_loggedin_user_fullname();
     1582
     1583                ob_start();
     1584
     1585                // Temporary override the displayed user by the logged in one.
     1586                add_filter( 'bp_displayed_user_id', 'bp_loggedin_user_id' );
     1587
     1588                bp_get_template_part( 'members/single/parts/item-nav' );
     1589                $widget_content = ob_get_clean();
     1590
     1591                // Remove the temporary override.
     1592                remove_filter( 'bp_displayed_user_id', 'bp_loggedin_user_id' );
     1593        } else {
     1594                ob_start();
     1595
     1596                if ( bp_is_user() ) {
     1597                        $widget_title = bp_get_displayed_user_fullname();
     1598                        bp_get_template_part( 'members/single/parts/item-nav' );
     1599                } elseif ( bp_is_group() ) {
     1600                        $widget_title = bp_get_current_group_name();
     1601                        bp_get_template_part( 'groups/single/parts/item-nav' );
     1602                } elseif ( bp_is_directory() ) {
     1603                        $widget_title = bp_get_directory_title( bp_current_component() );
     1604                        bp_get_template_part( 'common/nav/directory-nav' );
     1605                }
     1606
     1607                $widget_content = ob_get_clean();
     1608        }
     1609
     1610        if ( ! $widget_content ) {
     1611                return '';
     1612        }
     1613
     1614        // Set the Block's title.
     1615        if ( true === $block_args['displayTitle'] ) {
     1616                $widget_content = sprintf(
     1617                        '<h2 class="widget-title">%1$s</h2>
     1618                        %2$s',
     1619                        esc_html( $widget_title ),
     1620                        $widget_content
     1621                );
     1622        }
     1623
     1624        // Only add a block wrapper if not loaded into a Widgets sidebar.
     1625        if ( ! did_action( 'dynamic_sidebar_before' ) ) {
     1626                $classnames         = 'widget_nav_menu buddypress_object_nav buddypress widget';
     1627                $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) );
     1628
     1629                return sprintf(
     1630                        '<div %1$s>%2$s</div>',
     1631                        $wrapper_attributes,
     1632                        $widget_content
     1633                );
     1634        }
     1635
     1636        return $widget_content;
     1637}
  • new file src/bp-templates/bp-nouveau/sass/primary-nav.scss

    diff --git src/bp-templates/bp-nouveau/sass/primary-nav.scss src/bp-templates/bp-nouveau/sass/primary-nav.scss
    new file mode 100644
    index 000000000..e115e5d33
    - +  
     1// BP primary navigation - directory and single screens
     2
     3// all devices & generic styles sitewide
     4.buddypress_object_nav {
     5
     6        .bp-navs {
     7                background: transparent;
     8                clear: both;
     9                overflow: hidden;
     10
     11                ul {
     12                        margin: 0;
     13                        padding: 0;
     14
     15                        li {
     16                                list-style: none;
     17                                margin: 0;
     18                        }
     19
     20                        li.last {
     21
     22                                select {
     23                                        max-width: 185px;
     24                                }
     25                        }
     26
     27                        li {
     28
     29                                a,
     30                                span {
     31                                        border: 0;
     32                                        display: block;
     33                                        padding: 5px 10px;
     34                                        text-decoration: none;
     35                                }
     36
     37                                .count {
     38                                        background: #eaeaea;
     39                                        border: 1px solid #ccc;
     40                                        border-radius: 50%;
     41                                        color: #555;
     42                                        display: inline-block;
     43
     44                                        font-size: 12px;
     45                                        margin-left: 2px;
     46                                        padding: 3px 6px;
     47                                        text-align: center;
     48                                        vertical-align: middle;
     49                                }
     50                        }
     51
     52                        li.selected,
     53                        li.current {
     54
     55                                a {
     56                                        color: #333;
     57                                        opacity: 1;
     58
     59                                        .count {
     60                                                background-color: #fff;
     61                                        }
     62                                }
     63                        }
     64
     65                        li.dynamic,
     66                        li.dynamic.selected,
     67                        li.dynamic.current {
     68
     69                                a {
     70
     71                                        .count {
     72                                                background-color: #5087e5;
     73                                                border: 0;
     74                                                color: #fafafa;
     75                                        }
     76                                }
     77                        }
     78
     79                        li.dynamic {
     80
     81                                a:hover {
     82
     83                                        .count {
     84                                                background-color: #5087e5;
     85                                                border: 0;
     86                                                color: #fff;
     87                                        }
     88                                }
     89                        }
     90
     91                        li {
     92
     93                                a {
     94
     95                                        .count:empty {
     96                                                display: none;
     97                                        }
     98                                }
     99                        }
     100                }
     101        }
     102
     103        .main-navs.dir-navs {
     104                margin-bottom: 20px;
     105        }
     106
     107        .bp-navs.group-create-links {
     108
     109                ul {
     110
     111                        li:not(.current) {
     112                                color: #767676;
     113
     114                                a {
     115                                        color: #767676;
     116
     117                                        &:focus,
     118                                        &:hover {
     119                                                background: none;
     120                                                color: #555;
     121                                        }
     122                                }
     123
     124                                a[disabled] {
     125
     126                                        &:focus,
     127                                        &:hover {
     128                                                color: #767676;
     129                                        }
     130                                }
     131                        }
     132
     133                        li.current {
     134
     135                                a {
     136                                        text-align: center;
     137                                }
     138                        }
     139                }
     140        }
     141}
  • new file src/js/bp-core/js/blocks/primary-nav.js

    diff --git src/js/bp-core/js/blocks/primary-nav.js src/js/bp-core/js/blocks/primary-nav.js
    new file mode 100644
    index 000000000..efc451eea
    - +  
     1/**
     2 * WordPress dependencies.
     3 */
     4const {
     5        blocks: {
     6                registerBlockType,
     7        },
     8        i18n: {
     9                __,
     10        },
     11} = wp;
     12
     13/**
     14 * Internal dependencies.
     15 */
     16import editPrimaryNavBlock from './primary-nav/edit';
     17import transforms from './primary-nav/transforms';
     18
     19registerBlockType( 'bp/primary-nav', {
     20        title: __( 'Primary navigation', 'buddypress' ),
     21        description: __( 'Displays BuddyPress primary nav in the sidebar of your site. Make sure to use it as the first widget of the sidebar and only once.', 'buddypress' ),
     22        icon: {
     23                background: '#fff',
     24                foreground: '#d84800',
     25                src: 'buddicons-community',
     26        },
     27        category: 'buddypress',
     28        attributes: {
     29                displayTitle: {
     30                        type: 'boolean',
     31                        default: true,
     32                },
     33        },
     34        edit: editPrimaryNavBlock,
     35        transforms: transforms,
     36} );
  • new file src/js/bp-core/js/blocks/primary-nav/edit.js

    diff --git src/js/bp-core/js/blocks/primary-nav/edit.js src/js/bp-core/js/blocks/primary-nav/edit.js
    new file mode 100644
    index 000000000..8aa4b4375
    - +  
     1/**
     2 * WordPress dependencies.
     3 */
     4const {
     5        blockEditor: {
     6                InspectorControls,
     7        },
     8        components: {
     9                Disabled,
     10                Notice,
     11                PanelBody,
     12                ToggleControl,
     13        },
     14        element: {
     15                Fragment,
     16                createElement,
     17        },
     18        i18n: {
     19                __,
     20        },
     21} = wp;
     22
     23/**
     24 * BuddyPress dependencies.
     25 */
     26const {
     27        blockComponents: {
     28                ServerSideRender,
     29        },
     30        blockData: {
     31                getCurrentWidgetsSidebar,
     32        }
     33} = bp;
     34
     35const editPrimaryNavBlock = ( { attributes, setAttributes, clientId } ) => {
     36        const { displayTitle } = attributes;
     37        const currentSidebar = getCurrentWidgetsSidebar( clientId );
     38        const disabledSidebars = ['sidebar-buddypress-members', 'sidebar-buddypress-groups'];
     39
     40        if ( currentSidebar && currentSidebar.id && -1 !== disabledSidebars.indexOf( currentSidebar.id ) ) {
     41                return (
     42                        <Notice status="error" isDismissible={ false }>
     43                                <p>
     44                                        { __( 'The BuddyPress Primary Navigation block shouldn\'t be used into this widget area. Please remove it.', 'buddypress' ) }
     45                                </p>
     46                        </Notice>
     47                );
     48        }
     49
     50        return (
     51                <Fragment>
     52                        <InspectorControls>
     53                                <PanelBody title={ __( 'Settings', 'buddypress' ) } initialOpen={ true }>
     54                                        <ToggleControl
     55                                                label={ __( 'Include navigation title', 'buddypress' ) }
     56                                                checked={ !! displayTitle }
     57                                                onChange={ () => {
     58                                                        setAttributes( { displayTitle: ! displayTitle } );
     59                                                } }
     60                                        />
     61                                </PanelBody>
     62                        </InspectorControls>
     63                        <Disabled>
     64                                <ServerSideRender block="bp/primary-nav" attributes={ attributes } />
     65                        </Disabled>
     66                </Fragment>
     67        );
     68};
     69
     70export default editPrimaryNavBlock;
  • new file src/js/bp-core/js/blocks/primary-nav/transforms.js

    diff --git src/js/bp-core/js/blocks/primary-nav/transforms.js src/js/bp-core/js/blocks/primary-nav/transforms.js
    new file mode 100644
    index 000000000..ea9e49887
    - +  
     1/**
     2 * WordPress dependencies.
     3 */
     4 const {
     5        blocks: {
     6                createBlock,
     7        },
     8} = wp;
     9
     10/**
     11 * Transforms Legacy Widget to Primary Nav Block.
     12 *
     13 * @type {Object}
     14 */
     15const transforms = {
     16        from: [
     17                {
     18                        type: 'block',
     19                        blocks: [ 'core/legacy-widget' ],
     20                        isMatch: ( { idBase, instance } ) => {
     21                                if ( ! instance?.raw ) {
     22                                        return false;
     23                                }
     24
     25                                return idBase === 'bp_nouveau_sidebar_object_nav_widget';
     26                        },
     27                        transform: ( { instance } ) => {
     28                                return createBlock( 'bp/primary-nav', {
     29                                        displayTitle: instance.raw.bp_nouveau_widget_title,
     30                                } );
     31                        },
     32                },
     33        ],
     34};
     35
     36export default transforms;