CategoryModel::calculateDisplayAs PHP Method

calculateDisplayAs() public static method

Maintains backwards compatibilty with DisplayAs: Default-type categories by calculating the DisplayAs property into an expected DisplayAs type: Categories, Heading, or Discussions. Respects the now-deprecated config setting Vanilla.Categories.DoHeadings. Once we can be sure that all instances have their categories' DisplayAs properties explicitly set in the database (i.e., not Default) we can deprecate/remove this function.
public static calculateDisplayAs ( &$category )
$category The category to calculate the DisplayAs property for.
    public static function calculateDisplayAs(&$category)
    {
        if ($category['DisplayAs'] === 'Default') {
            if ($category['Depth'] <= c('Vanilla.Categories.NavDepth', 0)) {
                $category['DisplayAs'] = 'Categories';
            } elseif ($category['Depth'] == c('Vanilla.Categories.NavDepth', 0) + 1 && c('Vanilla.Categories.DoHeadings') && !self::$stopHeadingsCalculation) {
                $category['DisplayAs'] = 'Heading';
            } else {
                $category['DisplayAs'] = 'Discussions';
            }
        }
    }

Usage Example

 /**
  * Calculate dynamic data on a category.
  *
  * This method is passed as a callback by default in {@link setCalculator}, but may not show up as used.
  *
  * @param array &$category The category to calculate.
  */
 private function defaultCalculator(&$category)
 {
     $category['CountAllDiscussions'] = $category['CountDiscussions'];
     $category['CountAllComments'] = $category['CountComments'];
     //        $category['Url'] = self::categoryUrl($category, false, '/');
     $category['ChildIDs'] = [];
     //        if (val('Photo', $category)) {
     //            $category['PhotoUrl'] = Gdn_Upload::url($category['Photo']);
     //        } else {
     //            $category['PhotoUrl'] = '';
     //        }
     CategoryModel::calculateDisplayAs($category);
     if (!val('CssClass', $category)) {
         $category['CssClass'] = 'Category-' . $category['UrlCode'];
     }
     if (isset($category['AllowedDiscussionTypes']) && is_string($category['AllowedDiscussionTypes'])) {
         $category['AllowedDiscussionTypes'] = dbdecode($category['AllowedDiscussionTypes']);
     }
 }