Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Related content only accesible if published #3303

Closed
miguelavaqrod opened this issue Apr 2, 2015 · 4 comments
Closed

Related content only accesible if published #3303

miguelavaqrod opened this issue Apr 2, 2015 · 4 comments

Comments

@miguelavaqrod
Copy link

Hi,

I know that using bolt's backend, you can not assign a related content to a contenttype if it is not published, but, using extensions you can.
Problem arrises when you try to get that kind of related content by means of extensions.
Using the .related(...) method, if related content is, for example, "held", you are not able to get it.

.related(...) does not have any parameter to bypass status.
However, for example, getContent(...) from storage class has it...

Just with a small modification, we can get the best of both worlds...

In Content.php, locate the 'related' function:

public function related($filtercontenttype = null, $filterid = null)

and replace it with:

public function related($filtercontenttype = null, $filterid = null, $status = null)

(null as default guarantees that it does not break anything...)

A few lines below there is this sentence:

$where = array('id' => implode(' || ', $ids));

Jut add, below, these ones:

if(!empty($status)){
   $where['status'] = $status;
}

Now you can use mycontent.related('myrelated', null, '!'), so it bypass the status of the related content.
Obviously, you can filter using a specific status.

Sorry guys, for posting that information this way and do not to generate a pull request or similar.
That's because I do not master github yet and I do not want to break things... so.. if somebody thinks it's interesting and generates that pull request for me.. I promise a beer as reward!.

Thanks.
miguelav

@bobdenotter
Copy link
Member

Hey,

The idea is that by default only published content is fetched. Would it not be simpler to just set the ones you're making the 'related' to as 'published' as well?

Your solution would allow you to get them, but you still couldn't link to them. If you just need the information on that page, why not make the related items just 'published'?

(i took the liberty of adding some formatting to your issue, for readability ;-) )

@miguelavaqrod
Copy link
Author

Hi!

Maybe I did not explain myself so well... ;-)

Imagine that situation (a real one, I am working on, so we can have an e-commerce extension):

By means of some "forms" (frontend-based), you get information about an order.
Those forms are processed by an extension, and generates an entry in a predefined contenttype (contenttype 'orders', for example).
However, as that order is not paid, I set it as held.
Once the customer pays (by means of a payment gateway, for example) my extension handles that and set that order to 'published' (so we get a 'green' dot ;-).

However, in a control panel (frontend-based) I designed, so customers can access and check their orders (related content), you need to list all orders (held and published).
That's why I made that change to core code.

Sometimes, you need to show not published records in front-end.. extensions scope is infinite ;-)

Comments welcomed...

Thanks!

@miguelavaqrod
Copy link
Author

Bob...

Just an offtopic...

In Content.php, line 412..417:

            $filename = sprintf(
                '%s/files/%s/%s',
                $this->app['paths']['rootpath'],
                date('Y-m'),
                String::makeSafe($file['name'][0], false, '[]{}()')
            );

It seems that the first slash has to be removed...
I'm am getting paths like:
/MyPath//files/2015-04/myfile.ext

Dumping $this->app['paths']['rootpath'] shows that it has the ending slash by its own.

Thanks

@bobdenotter
Copy link
Member

I'm am getting paths like: /MyPath//files/2015-04/myfile.ext

I've made a PR for this..

Sometimes, you need to show not published records in front-end.. extensions scope is infinite ;-)

That's a good usecase. I'm going to make it slightly different though.. I don't like too many parameters, so i'd like to make it work like this:

public function related($filtercontenttype = null, $options = array() )

That way you can do mycontent.related('myrelated', {'status': '!'}).

GwendolenLynch added a commit that referenced this issue Apr 5, 2015
Allow filtering in 'record.related' on other fields too. Fixes #3303
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants