/** * Sets the views meta data, if available * * @param array $data * @return void */ public function set($data = array()) { $Model = $this->__controller->{$this->__controller->modelClass}; // assign the meta title variable, starting with data assigned // directly to MetaData, falling back next to the Model displayField // variable before falling again to the Model displayName variable if (!empty($data['MetaData']['title'])) { $metaTitle = $data['MetaData']['title']; } elseif (!empty($data[$Model->alias][$Model->displayField])) { $metaTitle = $data[$Model->alias][$Model->displayField]; } else { $metaTitle = Inflector::pluralize($data[$Model->alias][$Model->displayName]); } if (!empty($metaTitle)) { $this->Controller->set(compact('metaTitle')); } // assign the meta description variable, starting with data // assigned directly to MetaData, falling back to content // and then body fields from within the supplied data if (!empty($data['MetaData']['description'])) { $metaDescription = $data['MetaData']['description']; } elseif (!empty($data[$Model->alias]['body'])) { // truncate the content variable to a max of 160 characters // ref: https://moz.com/learn/seo/meta-description $metaDescription = CakeText::truncate($data['MetaData']['description'], 160, array('html' => false)); } elseif (!empty($data[$Model->alias]['content'])) { // truncate the content variable to a max of 160 characters // ref: https://moz.com/learn/seo/meta-description $metaDescription = CakeText::truncate($data[$Model->alias]['content'], 160, array('html' => false)); } if (!empty($metaDescription)) { $this->Controller->set(compact('metaDescription')); } return; }