Source of file WordpressPageContentItem.php
Size: 4,282 Bytes - Last Modified: 2021-12-23T10:49:12+00:00
/var/www/docs.ssmods.com/process/src/code/items/WordpressPageContentItem.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 | <?php /** * A content item that represents a wordpress page. * * @package silverstripe-wordpressconnector */ class WordpressPageContentItem extends ExternalContentItem { /** * @param array $data * @return WordpressPageContentItem */ public static function factory($source, $data) { $item = new self($source, $data['page_id']); $item->WordpressID = $data['page_id']; $item->CreatedAt = strtotime($data['dateCreated']); $item->UserID = $data['userid']; $item->Status = $data['page_status']; $item->Description = $data['description']; $item->Title = html_entity_decode($data['title']); $item->Link = $data['link']; $item->Permalink = $data['permaLink']; $item->Excerpt = $data['excerpt']; $item->TextMore = $data['text_more']; $item->AllowComments = $data['mt_allow_comments']; $item->AllowPings = $data['mt_allow_pings']; $item->Slug = $data['wp_slug']; $item->Password = $data['wp_password']; $item->Author = $data['wp_author']; $item->ParentID = $data['wp_page_parent_id']; $item->ParentTitle = $data['wp_page_parent_title']; $item->Order = $data['wp_page_order']; $item->AuthorID = $data['wp_author_id']; $item->AuthorName = $data['wp_author_display_name']; $item->Template = $data['wp_page_template']; $categories = new ArrayList(); foreach ($data['categories'] as $category) { $categories->push(new ArrayData(array( 'Name' => $category ))); } $item->Categories = $categories; $custom = new ArrayList(); foreach ($data['custom_fields'] as $field) { $custom->push(new ArrayData(array( 'ID' => $field['id'], 'Key' => $field['key'], 'Value' => $field['value'] ))); } $item->CustomFields = $custom; return $item; } public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab('Root.Details', new ReadonlyField( 'CategoryList', 'Categories', implode(', ', $this->Categories->map('Name', 'Name')) )); $fields->addFieldsToTab('Root.Users', array( new ReadonlyField('UserID', 'User ID', $this->UserID), new ReadonlyField('Author', null, $this->Author), new ReadonlyField('AuthorID', 'Author ID', $this->AuthorID), new ReadonlyField('AuthorName', 'Author Name', $this->AuthorName) )); $fields->addFieldsToTab('Root.Metadata', array( new ReadonlyField('Slug', null, $this->Slug), new ReadonlyField('Link', null, $this->Link), new ReadonlyField('Permalink', null, $this->Permalink) )); $fields->addFieldsToTab('Root.Behaviour', array( new ReadonlyField('ParentID', 'Parent ID', $this->ParentID), new ReadonlyField('ParentTitle', 'Parent Title', $this->ParentTitle), new ReadonlyField('AllowComments', 'Allow Comments', $this->AllowComments), new ReadonlyField('AllowPings', 'Allow Pings', $this->AllowPings), new ReadonlyField('Password', null, $this->Password), new ReadonlyField('Template', null, $this->Template), new ReadonlyField('Order', null, $this->Order) )); $fields->addFieldToTab( 'Root.CustomFields', ($custom = new GridField('CustomFields', null, $this->CustomFields, new GridFieldConfig_RecordViewer())) ); $config = $custom->getConfig(); $config->removeComponentsByType('GridFieldFilterHeader'); $config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array( 'ID' => 'ID', 'Key' => 'Key', 'Value' => 'Value' )); return $fields; } public function stageChildren($showAll = false) { return $this->source->getPagesByParentId($this->externalId); } public function getType() { return 'WpPage'; } } |